用sed 给文本文件加行号

简介:

看例子:

复制代码
[root@localhost tmp]# sed '=' test.txt
1
tsttst tsttsttst
2
west gao
3
west abces
[root@localhost tmp]# sed = test.txt | sed 'N;s/\n/\t/'
1       tsttst tsttsttst
2       west gao
3       west abces
[root@localhost tmp]# 
复制代码

N的解释:

N:Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands.






本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2013/01/09/2853406.html,如需转载请自行联系原作者

目录
相关文章
|
3月前
|
开发工具 Perl
使用sed去掉代码中的行号
使用sed去掉代码中的行号
使用sed去掉代码中的行号
|
8月前
|
机器学习/深度学习 存储 监控
sed命令(超详细)
是一种流编辑器,它是文本处理中非常好的工具,能够完美的配合正则表达式使用,功能不同凡响。 处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命 令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复, 直到文件末尾。
145 0
|
10月前
|
Perl
sed(按行操作)文本过滤
sed(按行操作)文本过滤
|
MySQL 关系型数据库 Perl
|
MySQL 关系型数据库 Shell
|
Perl Shell