When parsing multiple fields in a file using AWK, how do you group by one of the fields and parse by delimiters?
to clarify
If a file had
tom | 223-2222-4444 , randofield
ivan | 123-2422-4444 , random filed
... | and , are the delimiters ...
How would you group by the social security while parsing the (comma delimited) fields using awk and print it?
Could you give us a sample file what you want to print, and what does the "group" mean exactly?
1 Like
All I want to do is echo out so that the middle field is the first, using an awk statement. I just don't quite get how awk works and need an example of beginning, middle and end. I don't understand how to parse the fields either, when the delimiter changes.
It would rearrange each delimited field and echo ...
social security : 223-2222-4444 | name : tom | third field : randomfield
and would do it for each line...
it would end with an echo
Hi
Is this what you are looking for:
$ cat a
tom | 223-2222-4444 , randofield
ivan | 123-2422-4444 , random filed
$ awk -F'[,|]' '{print $2,$1, $3}' OFS="|" a
223-2222-4444 |tom | randofield
123-2422-4444 |ivan | random filed
Guru
1 Like
echo "tom | 223-2222-4444 , randofield" |awk '{print "social security : " $3 " | name : "$1" | third filed : "$NF}'
social security : 223-2222-4444 | name : tom | third filed : randofield