IT_User
IT_User

Reputation: 779

awk not working as expected

I have what I am assuming to be a very simple problem. I have used the following command in scripts many times before without issues.

display=/some/file/with/data
sed -i "s/$(more ${display} | grep 110 | gawk '{ print $3 }')/"replacestring"/g" ${display}

Never had an issue with this command.

I created a script that simplified everything that was needed and have the following code:

displayText=$(more ${display} | grep 110 | gawk '{ print $3 }')

I keep receiving

line 2: syntax error: unexpected end of file.

I am very familiar with Linux so the problem has been quite irritating as the answer has escaped me. Please assist.

Upvotes: 0

Views: 1459

Answers (1)

Brad Lanam
Brad Lanam

Reputation: 5763

Not sure why you are using more. You also have backquotes around the awk script where you should have single quotes.

displayText=$(cat ${display} | grep 110 | gawk '{ print $3 }')

You will be told that this is a useless-use-of-cat (the cat command isn't needed since grep can read a file). You can just do:

displayText=$(grep 110 ${display} | gawk '{ print $3 }')

As awk can also search, this can be simplified further into:

displayText=$(gawk '/110/ {print $3}'  ${display})

Upvotes: 1

Related Questions