Search code examples
awkseparator

Awkward: Combine two awk statements


I have a set of data that looks like this:

foo:123 bar baz
oof:2983 rab zdo 
mor:8 eoinn uiemdh

and what I'd like to have as result is:

123
2983
8

Assuming the data is in a file called test.txt, what I currently have is:

 awk '{print $1}' test.txt | awk -F: '{print $2}'

How can I combine those two statements?


Solution

  • You could sed the field separator to a regex:

    awk -F' |:' '{print $2}' file
    123
    2983
    8