介绍
cat (concatenate) 用于连接文件并打印它们的内容。
-b, --number-nonblank 对非空输出行编号,从 1 开始计数。
-e, 在每行的结尾显示一个美元符号 $
,这样你可以清楚地看到每行的结束。 -n, --number 由 1 开始对所有输出的行数编号 -s, --squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行 -s, --squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行
使用示例:
# 普通使用 ➜ linuxtest cat test1.txt justx 第一行文字 第二行文字 第三行蚊子 end # 非空编号 ➜ linuxtest cat -b test1.txt 1 justx 2 第一行文字 3 第二行文字 4 第三行蚊子 5 end # 所有行编号 ➜ linuxtest cat -n test1.txt 1 justx 2 3 4 第一行文字 5 6 第二行文字 7 8 第三行蚊子 9 10 11 end 12 # 连续空白行压缩为一行 ➜ linuxtest cat -s test1.txt justx 第一行文字 第二行文字 第三行蚊子 end # 查看多个文件 ➜ linuxtest cat -n test1.txt test2.txt 1 justx 2 3 4 第一行文字 5 6 第二行文字 7 8 第三行蚊子 9 10 11 end 12 1 test2 # 利用重定向功能,另存为拼接文件 -n 序号也会被写入test3.txt内容中 ➜ linuxtest cat -n test1.txt test2.txt >> test3.txt ➜ linuxtest cat -n test3.txt 1 1 justx 2 2 3 3 4 4 第一行文字 5 5 6 6 第二行文字 7 7 8 8 第三行蚊子 9 9 10 10 11 11 end 12 12 13 1 test2
文章评论