日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2025/4/16 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的几种用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。