Several columns to two column

Dear All,

I have file :
input.txt

HANDVEL 2201181                                                1000      180       
19      1540    173     1581    316     1652    509     1707    
653     1767    816     1834    951     1882    1100    1984    
1225    2050    1331    2109    1732    2491    1927    2665    
2237    2893    2351    2972    2563    3103    2785    3226    
3981    3900    
HANDVEL 2201189                                                1000      188       
24      1540    156     1580    295     1642    435     1679    
536     1695    641     1760    790     1811    906     1861    
1011    1935    1202    2039    1336    2116    1452    2225    
1766    2524    2180    2853    2308    2942    2998    3346    
3981    3901    

Desired output,
output.txt

HANDVEL 2201181                                                1000      180       
19      1540    
173     1581    
316     1652    
509     1707    
653     1767    
816     1834    
951     1882    
1100    1984    
1225    2050    
1331    2109    
1732    2491    
1927    2665    
2237    2893    
2351    2972    
2563    3103    
2785    3226    
3981    3900    
HANDVEL 2201189                                                1000      188       
24      1540    
156     1580    
295     1642    
435     1679    
536     1695    
641     1760    
790     1811    
906     1861    
1011    1935    
1202    2039    
1336    2116    
1452    2225    
1766    2524    
2180    2853    
2308    2942    
2998    3346    
3981    3901    

Any idea?

Thanks for advance,

Attila

awk '/HANDVEL/{print;next}{for (i=1;i<=NF;i=i+2) print $i,$(i+1)}' infile
1 Like
 
awk '/^[A-Z]/ {print $0} /^[0-9]/ { for (i=1;i<=NF;i=i+2) print $i,$(i+1) }' input.txt

Cheers,

1 Like

It solved, thank you rdcwayx & Joseph_TKLee

With Sed..

$ uname -rs
SunOS 5.10
$ sed -e '/HAND/!s/\([^ $]*  *[^ ]* *\)/\1\
> /g' -e 's/ *\n$//' inputfile

Similar fashion with awk..

nawk '/HAND/{print;next}{gsub(/[^ $]*  *[^ ]* */,"&\n");sub(/ *\n$/,"");print}' intputfile