Linux shell获取文件第一行或最后一行

Linux shell获取文件的最后一行,方法有: sed -n '1p' a.txtawk 'NR==1 {print}' a.txthead -n 1 a

Linux shell获取文件的最后一行,方法有:

sed -n '1p' a.txtawk 'NR==1 {print}' a.txthead -n 1 a.txt

Linux shell获取文件的最后一行,方法有:

sed -n '$p' a.txtawk 'END {print}' a.txttail -n 1 a.txt 

其中tail -n 1用于当文件较大时使用。