Using awk to cut fields and reduce dupes
First, let me provide some sample data.
Code:
Sam,,"Sam","I am" Sam "I am" "I don't like" "Green eggs and ham" This is what I wrote and all I am getting is field 4. I think I need to add the 'else' into the 'if' statement, but I dont know how to go about it. Code:
sort -d <file> | awk -F"," '{ if ($1 != last_name_seen) {print $4; last_name_seen=$1}}' S |
I tried this:
Quote:
Quote:
Quote:
|
You don't need an else, you just need to separate printing $1 (which you only want sometimes) from printing $4 (which you always want to do):
Code:
awk -F, '($1 != prev_name){printf("%s ", $1)} {print $4; prev_name = $1}' |
ntubski,
It works! Thank you. |
All times are GMT -5. The time now is 12:01 PM. |