unix でhead
andを使用して、ファイルの 2 行目から最終行の前の行までを選択するにはどうすればよいですか?tail
たとえば、ファイルに 15 行ある場合、2 行から 14 行までを選択したいとします。
tail -n +2 /path/to/file | head -n -1
perl -ne 'print if($.!=1 and !(eof))' your_file
以下でテスト:
> cat temp
1
2
3
4
5
6
7
> perl -ne 'print if($.!=1 and !(eof))' temp
2
3
4
5
6
>
または、awk で以下を使用できます。
awk '{a[count++]=$0}END{for(i=1;i<count-1;i++) print a[i]}' your_file