web-dev-qa-db-ja.com

bashの最初の行を削除する

Bashシェルでファイルの最初の行をすばやく削除する方法はありますか? sedやそのようなものを使用することを意味します。

14
GuillaumeThomas

特に明記しない限り、長さの逆順の1ライナー。

sedGNU sedには-iが必要です):

sed -i 1d file

ed (たとえば、$'...'の展開とここの文字列にはbashが必要です):

ed file <<< $'1d\nw\nq'

awk

awk NR\>1 infile > outfile

tail

tail -n +2 infile > outfile

read + cat

(read x; cat > outfile) < infile

bashビルトイン:

while IFS= read -r; do ((i++)) && printf %s\\n "$REPLY" >> outfile; done < infile
26
peth
$ tail -n +2 <<< $'1\n2\n3'
2
3

Ddの使用

 fn = "The-BIG-FILE.txt" 
 fll = $(($(head -n 1 $ fn | wc -c)+ 1))
 dd if = "$ fn" of = "$ {fn} .out" bs = 1M iflags = skip_bytes skip = $ fll 
 echo "ファイルは$(($(find $ fn * -printf"%s-\n "; echo" 0 ")))バイト。$ fnの最初の行は$ fllバイトです。" 

追加iflags=およびoflags=必要な場合があります-カンマで区切ります

0
Hannu