Green
Green

Reputation: 160

Bash: fixed variables change to changing variable

I am writing code which has to pick a specific line from the table. I am trying to pick the line and then put in a file with the name result_X_Y.txt.

I already tried $Xand $Y. Maybe there are some other options?

There is the line of code:

line=$(grep -F '21.581' cuted.txt | grep -F '54.6845')

this works very well when I put the numbers, but if I want to use these lines it does not work:

X=21.581

Y=54.6845

line=$(grep -F 'X' cuted.txt | grep -F 'Y')

Upvotes: 0

Views: 77

Answers (1)

qwsj
qwsj

Reputation: 456

You using grep with word X and Y, but it not a variable.

Try it: line=$(grep -F "$X" cuted.txt | grep -F "$Y")

Upvotes: 1

Related Questions