linux cat 脚本,Linux Shell 脚本攻略 读书笔记 -- 201.cat的几种用法
cat可以讀取、顯示和拼接文件內(nèi)容
1. 打印單個(gè)文件:
root@debian:/home/chicol/scripts# cat file.txt
This is a line inside file.txt
This is second line inside file.txt
打印多個(gè)文件:
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. 讀取標(biāo)準(zhǔn)輸入:
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
將標(biāo)準(zhǔn)輸入和文件內(nèi)容拼接:
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
這里將"-"當(dāng)作stdin文本的文件名。
3. cat打印文件內(nèi)容的幾個(gè)選項(xiàng)用法:
cat -s :當(dāng)文件中有連續(xù)空白行時(shí),使用-s選項(xiàng)打印時(shí),會(huì)去掉多余的空白行,只保留一個(gè)空白行
cat -n: 打印文件內(nèi)容時(shí)顯示行號(hào)
cat -T: 可以區(qū)別顯示制表符和空格,制表符顯示為“^I”
這里來(lái)看下這幾個(gè)選項(xiàng)在一起使用的例子:
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) | 評(píng)論(0) | 轉(zhuǎn)發(fā)(0) |
總結(jié)
以上是生活随笔為你收集整理的linux cat 脚本,Linux Shell 脚本攻略 读书笔记 -- 201.cat的几种用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux设置账号权限设置,Linux账
- 下一篇: linux gdal安装错误,CentO