awk按列合并兩個文件
new_retain.txt
2017-01-01|121419|17844
2017-01-02|111997|14747
2017-01-03|98559|13898
active.txt
2017-01-01|4552854
2017-01-02|4254646
2017-01-03|3980417
awk '{if(NR==FNR){a[FNR]=$1;}else{print $1 "|" a[FNR]}}' new_retain.txt active.txt > new.txt
命令執行完成后,new.txt內容如下
2017-01-01|4552854|2017-01-01|121419|17844
2017-01-02|4254646|2017-01-02|111997|14747
2017-01-03|3980417|2017-01-03|98559|13898
2017-01-01|121419|17844
2017-01-02|111997|14747
2017-01-03|98559|13898
active.txt
2017-01-01|4552854
2017-01-02|4254646
2017-01-03|3980417
awk '{if(NR==FNR){a[FNR]=$1;}else{print $1 "|" a[FNR]}}' new_retain.txt active.txt > new.txt
命令執行完成后,new.txt內容如下
2017-01-01|4552854|2017-01-01|121419|17844
2017-01-02|4254646|2017-01-02|111997|14747
2017-01-03|3980417|2017-01-03|98559|13898
posted on 2017-02-16 20:43 小一敗涂地 閱讀(1360) 評論(0) 編輯 收藏 所屬分類: linux相關