I have a say a.txt file, and below is its contents:
bob 1 100 lincoln 2 200 chris 3 300
The contents of the file are separated by a space.
Using awk, I can access each column. Using the command below to print the 1st and 3rd columns, separated by a comma:
cat a.txt | awk ' { print $1","$3} '
and i was successful.
Now I want to dynamically pass criteria from another shell script. Speaking of criteria, I mean - $1","$3 .
I tried the command below, but that didn't work.
myvar="$1" awk -va="$myvar" ' { print a } ' a.txt
but this prints $1 3 times since a.txt has three lines.
How to pass a list of awk fields this way?
source share