1

I am trying to make a simple bash script that uses command line arguments as parameters to awk.

The file format is like this:

id|Name|birthday|joinDate

And the command line input:

./my_script -f filename.dat -id 1234

When I use the following line of code:

awk -v arg ="$4", -F"|" '{if(arg == $1)print $1,$2}' "$2"

I get an error that says:

'awk: 'arg' argument to '-v' not in 'var=value' form'.

What's wrong with this? All I want is to print specific columns of the given ID.

1 Answer 1

9

Your answer is in the error message. Put the argument in var=value form, without any spaces around = sign.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.