linux cat 脚本,Linux Shell 脚本攻略 读书笔记 -- 201.cat的几种用法

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#

阅读(670) | 评论(0) | 转发(0) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值