`
icepp
  • 浏览: 10398 次
  • 性别: Icon_minigender_1
  • 来自: 大连
最近访客 更多访客>>
社区版块
存档分类
最新评论

对sed1line中一些命令的理解 三

阅读更多

 

# number each line of a file (simple left alignment) Using a tab (see 
# note on '\t' at end of file)instead of space will preserve margins. 
#给文件每一行加上数字序号。用TAB制表符替换空间来保留空白 
#(在数字序号和文本中间加一TAB制表符) 
sed = filename | sed 'N;s/\n/\t/'

 N    append the next line of input into the pattern space.
 =     Print the current line number.
 注意=是将当前行号作为一行写到stdout.

 

这个比较简单的说 :)

Sed = filename通过管道输入给sed 'N;s/\n/\t/'
管道后的语句就是将行号和内容行连起来,将行号后的\n替换成\t,OK

 

# number each line of a file (nnumber on left, right-aligned) 
#给文件每一行加上数字序号(数字在左边,数字右边内容对齐) 
sed = filename | sed 'N; s/^/     /; s/ *\(.\{6,\}\)\n/\1  /'
这个就是对正则表达式的理解,注意空格

 这个就是对正则表达式的理解,注意空格。

 

# number each line of file, but only print numbers if line is not blank 
#给文件每一行加上数字序号,但是仅当行非空时打印数字 
sed '/./=' filename | sed '/./N; s/\n/ /'

 这个也很简单,就不说了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics