文件操作与重定向实用指南
在文件处理和脚本编写过程中,掌握一些不太常见但实用的功能可以显著提高效率。以下将详细介绍文件操作和重定向的相关内容。
1. 行编号
在处理代码行、配置文件或其他文本文件时,显示每行的行号非常有用。 cat 命令的 -n 选项可以实现这一功能。
$ cat -n file1 file2
1 this is file1
2
3 it has four lines.
4 the second is blank.
5 this is file2
6
7 it has six lines (three blank)
8
9
10 of which this is the sixth.
$
若要为每个文件单独编号,需要为每个文件使用一个 cat 命令,命令之间用分号分隔:
$ cat -n file1 ; cat -n file2
1 this is file1
2
3 it has four lines.
4 the second is blank.
1 this is file2
2
3 it has six lines (three blank)
4
超级会员免费看
订阅专栏 解锁全文
1151

被折叠的 条评论
为什么被折叠?



