I have two files: data.csv and list.txt. Here's an example of what they look like
data.csv:
"John","red","4"
"Basketball","orange","2"
"The Mike","blue","94"
"Lizard","purple","3"
"Johnny","pink","32"
list.txt:
Mike
John
purple
32
Now, I am trying to figure out how I can make a loop
awk -F "\"*,\"*" '/**LIST ITEM**/ {print $1}' data.csv > output.txt
where the command runs for each line of list.txt, replacing **LIST ITEM**. How can this be accomplished?
I'm running this though Terminal on MacOSX 10.5.7.
EDIT:
The desired output for the above example would be
The Mike
John
Johnny
Lizard
Johnny
EDIT2:
To be more clear, I am trying to avoid doing this:
awk -F "\"*,\"*" '/Mike/ {print $1}' data.csv
awk -F "\"*,\"*" '/John/ {print $1}' data.csv
awk -F "\"*,\"*" '/purple/ {print $1}' data.csv
awk -F "\"*,\"*" '/32/ {print $1}' data.csv
And instead, run it in one command, somehow looping through all the lines of list.txt.
LIST ITEM
somewhere (assuming it's literal) as well as providing desired output – SiegeX Mar 9 '11 at 5:41**LIST ITEM**
, it appears you mean the first field of your CSV, yes? Also, I believe your desired output is wrong, there is an extraJohnny
line, yes? – SiegeX Mar 9 '11 at 5:58awk -F "\"*,\"*" '/32/ {print $1}' data.csv
would yieldJohnny
, unless I am mistaken. – Julien Mar 9 '11 at 6:04