網站首頁 編程語言 正文
目錄
- cat命令
- 1 cat在查看文件內容時同時輸出行號應該怎么做?
- 2 more 命令
- 3 grep命令
- 4 head , tail 命令
- 1 head 查看內容
- 2 tail 查看內容
- cut命令
- 1 要求剪切后輸出第一個字段
- 2 輸出第一字段和第三字段內容
- uniq命令
- 1 使用uniq命令輸出去重后的結果
- 2 使用uniq命令只輸出重復的行
- 3 使用uniq命令統(tǒng)計重復的次數(shù)
- sort命令
- 1 對num.txt排序,并且將結果輸出到sorted_num.txt中
- 2 對args.txt排序,并且將結果輸出到sorted_args.txt中
- 3 對args.txt和num.txt排序,并將結果輸出到sorted_merge.txt中
- 4 對args.txt排序后去重輸出合并sorted_args.txt和sorted_num.txt且輸出給定文件info.txt按第二列作為key進行排序
- tr命令
- 1 將后14個英文字母變成大寫
- 2 將文件中數(shù)字變?yōu)榭兆址?/li>
- 結束
cat命令
1 cat在查看文件內容時同時輸出行號應該怎么做?
如下:查看/etc/passwd/下的內容并且輸出行號
注意:/etc/passwd/ 這個文件下不是關于密碼的配置文件,而是關乎于用戶的配置文件。
命令:
[root@localhost Desktop]# cat -n /etc/passwd
2 more 命令
例:還是查看/etc/passwd目錄下的內容:
more命令:
[root@localhost Desktop]# more -p10 /etc/passwd
3 grep命令
例: 查看/etc/passwd 中和root相關的內容:
命令:
[root@localhost Desktop]# grep -G "root" /etc/passwd
4 head , tail 命令
1 head 查看內容
例:查看 /etc/passwd 內容的前5行內容:
命令:
[root@localhost Desktop]# head -n 5 /etc/passwd
默認是輸出10行
2 tail 查看內容
例:查看 /etc/passwd 內容的前5行內容:
命令:
[root@localhost Desktop]# tail -n 5 /etc/passwd
默認輸出也是10行。
cut命令
首先創(chuàng)建一個文件:cut_data.txt ,且內容為:
No Name Score
1 zhang 20
2 li 80
2 wang 90
4 sun 60
1 要求剪切后輸出第一個字段
命令:
[root@localhost Desktop]# cut -b 1-2 cut_data
結果如下:
按字節(jié)切割,輸出切割后的第一個字節(jié)到第10個字節(jié)的內容:
[root@localhost Desktop]# cut -b 1-10 cut_data
按字符切割,輸出切割后的第一個字符到第5個字符的內容:
[root@localhost Desktop]# cut -c 1-5 cut_data
將上面文件內容改為:
No|Name|Score
1|zhang|20
2|li|80
2|wang|90
4|sun|60
2 輸出第一字段和第三字段內容
說明:因為這里是以 | 作為分隔的所以在用分隔條件時需要加上轉義符 ** ,所以是 -d| 。整個命令解釋是:將cut_data整個文件的內容作為標準輸入到cut語句中,以 | 為分界符(可知分成了3個域),剪切出第1和3域。
命令和輸出如下:
[root@localhost Desktop]# cat cut_data | cut -d\| -f 1,3
No|Score
1|20
2|80
2|90
4|60
uniq命令
新建文件uniq_data.txt 并且內容寫:
Welcome to Linux
Windows
Windows
Mac
Mac
Linux
1 使用uniq命令輸出去重后的結果
命令及輸出結果:
[root@localhost Desktop]# uniq uniq_data.txt
Welcome to Linux
Windows
Mac
Linux
注意:默認是去重
2 使用uniq命令只輸出重復的行
命令及輸出結果:
[root@localhost Desktop]# uniq -d uniq_data.txt
Windows
Mac
3 使用uniq命令統(tǒng)計重復的次數(shù)
命令及結果:
[root@localhost Desktop]# uniq -c uniq_data.txt
1 Welcome to Linux
2 Windows
2 Mac
1 Linux
注意數(shù)字代表重復個數(shù)
sort命令
例:給定文件num.txt, args.txt
內容:
num.txt:
1
3
5
2
4
注意第一行有一個空格。
args.txt內容:
args1
args2
args4
args4
args3
1 對num.txt排序,并且將結果輸出到sorted_num.txt中
首先創(chuàng)建文件寫入內容不用說了。
命令及結果:
[root@localhost Desktop]# sort -n num.txt > sorted_num.txt
1
2
3
4
5
注意: -b 參數(shù)是不管開頭的空白,但這里不加這個參數(shù)好像也行。
2 對args.txt排序,并且將結果輸出到sorted_args.txt中
命令及顯示結果:
[root@localhost Desktop]# cat sorted_args.txt
[root@localhost Desktop]# cat sorted_args.txt
args1
args2
args3
args4
args4
3 對args.txt和num.txt排序,并將結果輸出到sorted_merge.txt中
命令及結果:
[root@localhost Desktop]# sort -n args.txt num.txt > sorted_merge.txt
[root@localhost Desktop]# cat sorted_merge.txt
args1
args2
args3
args4
args4
1
2
3
4
5
4 對args.txt排序后去重輸出合并sorted_args.txt和sorted_num.txt且輸出給定文件info.txt按第二列作為key進行排序
命令及結果:
[root@localhost Desktop]# sort args.txt | uniq | cat sorted_args.txt sorted_num.txt > info.txt | sort -k 2
注意:這個命令本人不確定對不對,應該與描述的命令一樣
tr命令
1 將后14個英文字母變成大寫
如下命令及結果:
[root@localhost Desktop]# tr m-z M-Z
abcdefghijklmnopqrstuvwxyz
abcdefghijklMNOPQRSTUVWXYZ
2 將文件中數(shù)字變?yōu)榭兆址?/h2>
aaa.txt中寫入:
hello 123 world 456
命令及結果:
[root@localhost Desktop]# cat aaa.txt | tr 0-9 " "-" "
hello world
注意:" “-” " 。 ""號中間有個空格
結束
原文鏈接:https://blog.csdn.net/fuyuo/article/details/125823897
相關推薦
- 2023-03-29 Pytorch框架之one_hot編碼函數(shù)解讀_python
- 2022-10-08 C語言實現(xiàn)影院管理系統(tǒng)程序設計_C 語言
- 2023-10-09 時間戳轉日期格式-自動補零,日期格式轉時間戳
- 2022-12-08 C#與C++?dll之間傳遞字符串string?wchar_t*?char*?IntPtr問題_C#
- 2022-09-23 opencv實現(xiàn)車牌識別_python
- 2022-09-04 C語言中反斜杠的作用及說明_C 語言
- 2022-06-07 C++實現(xiàn)關系與關系矩陣的代碼詳解_C 語言
- 2023-01-15 RUST異步流處理方法詳細講解_Rust語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支