曲径通幽论坛

标题: $. -- 当前行号 [打印本页]

作者: beyes    时间: 2012-7-18 16:00
标题: $. -- 当前行号
$. 是个预定义变量,表示当前行号。

测试文本:
$ cat tmp.txt
hello world
hello linux
hello perl

希望在输出时给每行添加一个行号,那么可以如下运行命令:
$ perl -n -e 'print "$.\. $_"' tmp.txt
1. hello world
2. hello linux
3. hello perl
在命令中 -e 选项后接 perl 执行语句。-n 选项表示循环从标准输入读入。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2