Hi All,
I have been trying to understand from the online awk manuals how to phrase this command line, but would greatly appreciate some help please.
I have a file (temp.txt) with these contents (one field per line, blank line separates records):
Code:
1st record, 1st field cat
1st record, 2nd field dog
1st record, 3rd field duck
1st record, 4th field cow
2nd record, 1st field car
2nd record, 2nd field boat
2nd record, 3rd field plane
2nd record, 4th field train
3rd record, 1st field plate
3rd record, 2nd field cup
3rd record, 3rd field fork
3rd record, 4th field knife
I want to find the record with the value "knife" for e.g. and print out the first field. This is what I have come up with so far:
Code:
awk -F=/ "/knife/ {print \$2}" RS="" "temp.txt"
I understand I need to change the field separator to a newline and record separator to a blank line, but I am getting really confused about how.
Also, does awk support the notion of saying "search for the value in the first field" etc?
Thank you for any assistance!