---
title: "对sed1line中一些命令的理解 三"
author: "icepp"
date: "2009-03-01T11:18:20Z"
tags: []
slug: "sed1line"
draft: false
lastmod: "2009-03-01T11:19:33Z"
id: 340938
url: "https://icepp.iteye.com/blog/340938"
---

```
# 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/ /'
```

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