大佬教程收集整理的这篇文章主要介绍了linux – 使用其他文件中的行号从文本文件中删除行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
lines.txt
1 2 4 5 22 36 400 ...
和documents.txt
String1 String2 String3 ...
sed -i’1d,4d,5d’documents.txt.
但是我必须删除很多行号.另外,我可以使用bash / perl脚本将行号存储在数组中,并回显不在数组中的行.但我想知道是否有内置命令来做到这一点.
任何帮助将受到高度赞赏.
@H_197_2@
kent$ head lines.txt doc.txt ==> lines.txt <== 1 3 5 7 ==> doc.txt <== a b c d e f g h kent$ awk 'NR==FNR{l[$0];next;} !(FNR in l)' lines.txt doc.txt b d f h
正如Levon所说,我补充一些解释:
awk # the awk command 'NR==FNR{l[$0];next;} # process the first file(lines.txt),save each line(the line# you want to Delete) into an array "l" !(FNR in l)' #Now come to the 2nd file(doc.txt),if line number not in "l",print the line out lines.txt # 1st argument,file:lines.txt docs.txt # 2nd argument,file:doc.txt@H_197_2@ @H_197_2@
以上是大佬教程为你收集整理的linux – 使用其他文件中的行号从文本文件中删除行全部内容,希望文章能够帮你解决linux – 使用其他文件中的行号从文本文件中删除行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。