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) |
總結
以上是生活随笔為你收集整理的linux cat 脚本,Linux Shell 脚本攻略 读书笔记 -- 201.cat的几种用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux设置账号权限设置,Linux账
- 下一篇: linux gdal安装错误,CentO