I'm trying to concatenate two lines when the number of fiels does not match a given number.
Here is an example of input file:
1, z
2
3
4
5, w
6
7
and here is the result I want:
1, z 2
3
4
5, w 6
7
I tried the following code:
awk '
{
if (NF!=1){
first=$0
getline
print first" ",$0}
else {print $0}
}' $1
Here is what I obtain:
2 z
3
4
6 w
7
I don't understand why I get the next line first and then only the second field of the first line.
A much more shorter version would be
ORS
is output field separatorFS
field separator, which is space by defaultNF == 1?"\n":FS'
ifNF
, number of fields equals to1
thenORS
is set to\n
else is set toFS