Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a variable by a special character

Tags:

I have value which stores the present resolution, such as: $2 = 1920x1080. I would like to split the value based on the x character and store the result in 2 variables. With the example above, the first variable will store 1920 and the second 1080. I would then like to make the definition for a print command based on these two valyues.

What is the best way to do this?

like image 843
Shira Avatar asked Jun 08 '11 20:06

Shira


1 Answers

awk '{    res=$2    split(res,resArr,"x")    print "resX=" resArr[1] "\tresY="resArr[2] }' inFile 

If I understand your needs correctly.

I hope this helps.

like image 196
shellter Avatar answered Oct 03 '22 02:10

shellter