Linux/Unix查看文件时,如何添加行号

时间:2019-11-20 08:53:50  来源:igfitidea点击:

在Linux中查看文件时,如何在左边显示行号?

示例

cat命令的语法为:

cat -n file
cat -n /etc/hosts

nl命令语法为:

nl file
nl /etc/hosts

less命令语法为:

less -N file
less -N /etc/hosts

awk命令语法为:

awk '{ print FNR " " 
perl -pe '$_ = "$. $_"' file
perl -pe '$_ = "$. $_"' /etc/hosts
}' file awk '{ print FNR " " ##代码## }' /etc/hosts awk '{ print FNR "\t" ##代码## }' /etc/hosts

perl的语法是:

##代码##