if statement - Find same name of text file like in the first column and print text if condition is true -


i have 1 text file , folder text files, delimited tab. use condition if value smaller 0 print specific text file condition.

for example:

  1. file:
112   0.6 116  -0.3 198  -0.7 205   0.4 
  1. folder, 4 files same name in 1. file in first column.
112.tsv 116.tsv -here add last row "this row want" 198.tsv -here add last row "this row want" 205.tsv 

i use awk code:

awk '{if ($2<=0); print "this row want" "?? file same name $1 ??"}' 1.file 

please me?

something (untested) it:

awk '$2<0 { print "this row want" >> ("folder/"$1".tsv") }' file 

you might need add ;close("folder/"$1".tsv") after print if aren't using gnu awk , can have lot of files open simultaneously .


Comments