linux - Awk stop processing in case of only head row is existed in the file -


i have 1 awk process below

awk 'fnr==1 && nr!=1 { while (/1name/) getline; } 1 { print } ' *.test.final | sort -t $'\t' -k1,1 > test.out 

this combine multiple files have extension .test.final.

each files has same format below

test1.test.final

1name    column1     column2 test1_1      5          4 test1_2      3          2 

another file test2.test.final

1name    column1     column2 test2_1      2          4 test2_2      3          2 

so final results below,

1name    column1     column2 test1_1      5          4 test1_2      3          2 test2_1      2          4 test2_2      3          2 

but times stopped processing in case there no data existed in file.

like below,

test3.test.final

1name    column1     column2 

it stop , not process

anyone know why , how fix this? files tab delimited.

thanks

i think overcomplicating code using while , getline.

just skip header of files when not first one. on rest of cases, print normally:

awk 'fnr==1 && nr!=1 {next} 1' *.test.final 

tested *.test.final files , worked well:

$ awk 'fnr==1 && nr!=1 {next} 1' *.final 1name    column1     column2 test1_1      5          4 test1_2      3          2 test2_1      2          4 test2_2      3          2 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -