用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.

原文地址:https://www.cnblogs.com/gaojian/p/2853406.html