Reputation: 3334
I have one text file and folder with another text files, delimited by tab. I would like to use condition if value smaller than 0 print specific text to another file with another condition.
For example:
112 0.6 116 -0.3 198 -0.7 205 0.4
112.tsv 116.tsv -here i would like to add last row with "This is the row what I want" 198.tsv -here i would like to add last row with "This is the row what I want" 205.tsv
I would like to use awk code:
awk '{if ($2<=0); print "This is the row what I want" "?? to file with same name like $1 ??"}' 1.file
Please could you help me?
Upvotes: 0
Views: 31
Reputation: 203209
Something like this (untested) will do it:
awk '$2<0 { print "This is the row what I want" >> ("folder/"$1".tsv") }' file
You MIGHT need to add a ;close("folder/"$1".tsv")
after the print if you aren't using GNU awk and can have a lot of files open simultaneously .
Upvotes: 1