Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1435017
  • 博文数量: 165
  • 博客积分: 2068
  • 博客等级: 上尉
  • 技术积分: 2102
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-27 16:07
文章分类

全部博文(165)

文章存档

2018年(1)

2017年(22)

2016年(9)

2015年(22)

2014年(8)

2013年(25)

2012年(53)

2011年(25)

分类: Python/Ruby

2015-10-12 20:55:24

cat可以读取、显示和拼接文件内容
1. 打印单个文件:
root@debian:/home/chicol/scripts# cat file.txt 
This is a line inside file.txt
This is second line inside file.txt
打印多个文件:
root@debian:/home/chicol/scripts# cat one.txt two.txt 
This is line from one.txt
This is line from two.txt
root@debian:/home/chicol/scripts# 
2. 读取标准输入:
root@debian:/home/chicol/scripts# ls | cat
1
1_12fname.sh
a1
a2
a3
calcu.sh
file.txt
functions.sh
ifs2.sh
ifs.sh
null
one.txt
out.txt
password.sh
printf.sh
sleep.sh
test1.sh
text.txt
three.txt
time_take.sh
tmp.txt
two.txt
将标准输入和文件内容拼接:
root@debian:/home/chicol/scripts# ls | cat - file.txt 
1
1_12fname.sh
a1
a2
a3
calcu.sh
file.txt
functions.sh
ifs2.sh
ifs.sh
null
one.txt
out.txt
password.sh
printf.sh
sleep.sh
test1.sh
text.txt
three.txt
time_take.sh
tmp.txt
two.txt
This is a line inside file.txt
This is second line inside file.txt
这里将"-"当作stdin文本的文件名。
3. cat打印文件内容的几个选项用法:
cat -s :当文件中有连续空白行时,使用-s选项打印时,会去掉多余的空白行,只保留一个空白行
cat -n: 打印文件内容时显示行号
cat -T: 可以区别显示制表符和空格,制表符显示为“^I”
这里来看下这几个选项在一起使用的例子:

root@debian:/home/chicol/scripts# cat three.txt 
This is first line.


This is second line






This is third line.
        Tab line.
        Space line.
root@debian:/home/chicol/scripts# cat -snT three.txt 
     1  This is first line.
     2
     3  This is second line
     4
     5  This is third line.
     6  ^ITab line.
     7          Space line.
root@debian:/home/chicol/scripts# 

阅读(1028) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~