I have this file
myfile
a b c d e 1
b c s d e 1
a b d e f 2
d f g h j 2
awk 'if $6==$variable {print @0}' myfile
How can I use this code in shell script that get $variable as parameter by user in command prompt?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
awk‘s-vflag. And sinceawkprints by default, you can try for example:Results:
EDIT:
The command is essentially the same, wrapped up in shell. You can use it in a shell script with multiple arguments like this
script.sh 2 jContents of
script.sh:Results: