我有兩個文件,一個只包含數據,它是這樣的「CSV固定寬度」(我將這裏的簡化版本數據,原始數據中有更多的列和行):Linux shell:如何根據另一個索引從一個文件中刪除行
1 "john smith" other fields
2 "john doe" other fields
3 "john black" other fields
4 "john brown" other fields
5 "john white" other fields
第一列包含索引,並且字段以5個字符填充。
第二個文件就是:
2
4
我想獲得的是隻包含有沒有在第二個文件的索引行第3檔。所以:
1 "john smith" other fields
3 "john black" other fields
5 "john white" other fields
我嘗試了不同的命令,awk
,grep
,join
,tr
等,但我無法得到它。
例子:
join -1 1 -2 1 file1.txt file2.txt
awk 'NR==FNR{a[NR]=$0; next} {print a[FNR], $0}' file1.txt file2.txt
任何幫助嗎?
請在這裏張貼您的企圖! – Fazlin
CSV和固定寬度是互斥的;要麼使用固定字符分隔列,要麼使用列的寬度來隱含每列之間的邊界。 – chepner