2016-08-01 65 views
0

我有一個文本文件和其他文本文件夾,由製表符分隔。如果值小於0,我想使用條件將特定文本打印到具有其他條件的另一個文件中。查找與第一列相同的文本文件的名稱,如果條件爲真,則輸出文本

例如:

  1. 文件:
112 0.6 
116 -0.3 
198 -0.7 
205 0.4 
  • 文件夾,其中是4個文件具有相同名稱的像在1。文件在第一列。
  • 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 
    

    我想用awk代碼:

    awk '{if ($2<=0); print "This is the row what I want" "?? to file with same name like $1 ??"}' 1.file 
    

    請你能幫助我嗎?

    回答

    1

    像這樣(未經)將做到這一點:

    awk '$2<0 { print "This is the row what I want" >> ("folder/"$1".tsv") }' file 
    

    您可能需要,如果你不使用GNU awk的,可以有很多文件同時打開打印後添加;close("folder/"$1".tsv")

    +1

    效果很好,謝謝埃德。 – Vonton

    相關問題