2017-03-15 181 views
1

我想使用sed刪除文本文件的前100行。我知道如何使用刪除第一行:sed:如何刪除文本文件的前100行

sed '1d' filename 

或鍵入

sed '100d' filename 

第100行如何指定一個範圍?我認爲這樣的事情會起作用:

sed '1:100d' filename 

但是,這顯然沒有奏效。有人可以告訴我如何指定一個範圍?在此先感謝您的幫助。

+0

','而不是':'? –

+1

[刪除SED或AWK文件中的行]可能出現重複(http://stackoverflow.com/questions/5721524/delete-lines-from-file-with-sed-or-awk) – Cyrus

回答

2

這應該工作在GNU sed的

sed '1,100d' file 
0

awk也可用於打印基於與行條件的數據。

像:繼將打印(在AWK而言紀錄),其數量是大於100

awk 'NR>100' inputfile 

你也可以使用其他條件,如線:

awk 'NR==100' inpuftile #this will print the 100th line 
awk 'NR<100' inputfile  #this will print 1-99th line 
awk 'NR>100' inputfile  #this will print from 101st line onwards 
awk 'NR>=100' inputfile #this will print from 100th onwards