tags:

views:

70

answers:

1

I have this input file (space is the separator for the two elements in the line otherwise there is just one element)

a:1
a:1 123
b:2 345 
c:3 456 
d:4 
d:4 456
..
..

I am interested in the output to be

a:1 123
d:4 456

i.e lines which have the preceding field to have just one field.

+1  A: 

Try this:

 { if (NF == 1) { getline; print; next; } }
Aaron Digulla
or just: NF == 1 {getline; print}
glenn jackman
I'll never get used to the conditional form in AWK :)
Aaron Digulla
It's actually pretty simple: pattern {action} pattern {action} ... pairs. If pattern matches perform the action. If pattern is omitted, always perform the action. If action is omitted, the default action is to print the current line.
glenn jackman