awk oneliner应该适合你,请看下面的测试:
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