文章目录
shell入门系列( 五 )cat
简介
cat 命令用于连接文件并打印到标准输出设备上。主要用于读取文件,拼接文件
简单demo
1.查看文件内容
准备两个文件的内容如下!
file1
one
one one
one one one
file2
two
two tow
tow tow
查看file1
cat file1
cat file2
cat file1 file2
效果
2 -
号的使用
-
代表cat
要从标准输入读取内容,按ctrl+d
结束输入,后面还可以加上其他输入源,比如文件
cat - file1 file2
效果
注意: 由于
ctrl+d
是我这个连接工具的快捷键 复制,才会出现这个问题。
3 管道与cat
echo "标准输入" | cat - file1 file2
效果
4 -s
去掉重复空行
修改文件 file2
file2
two
two tow
tow tow
操作
cat -s file2
效果
5 消除空行,管道替换空行
cat file2 | tr -s '\n'
效果
6 制表符特殊输出 -T
改变文件内容file2
file2
two
two tow
tow tow
echo "hello"
printf("hello")
return;
操作
cat -T file2
效果
7 显示行号 -n
操作
cat -n file2
ls -l | cat -n