歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux命令裡面兩個很經典的命令:join和tr

下面先看一下join命令的使用方法:
對於合並兩個具有相同文件頭的方法合並起來是一種很好的方法:

[www.linuxidc.com @linux source]$cat sinadept.txt
100 Harry Potter:100:Magic School
200 Alex Jason:200:Sales
300 Yu Chao:300:SINA Product Development
400 Sanjay Gupta:400:Support
500 Nisha Singh:500:Sales
1000 Yu Jun:1000:Peking University EECS
[www.linuxidc.com @linux source]$cat sinasalary.txt
100 $1000
200 $1234
300 $892
400 $2389
500 $123
1000 $2389
[www.linuxidc.com @linux source]$join sinadept.txt sinasalary.txt
100 Harry Potter:100:Magic School $1000
200 Alex Jason:200:Sales $1234
300 Yu Chao:300:SINA Product Development $892
400 Sanjay Gupta:400:Support $2389
500 Nisha Singh:500:Sales $123
1000 Yu Jun:1000:Peking University EECS $2389
[www.linuxidc.com @linux source]$join sinasalary.txt sinadept.txt
100 $1000 Harry Potter:100:Magic School
200 $1234 Alex Jason:200:Sales
300 $892  Yu Chao:300:SINA Product Development
400 $2389 Sanjay Gupta:400:Support
500 $123 Nisha Singh:500:Sales
1000 $2389 Yu Jun:1000:Peking University EECS

再看一下tr命令,對於需要執行整篇文章進行大小寫轉換的處理時很有用:

如下:

[www.linuxidc.com @linux source]$tr a-z A-Z <sinadept.txt
100 HARRY POTTER:100:MAGIC SCHOOL
200 ALEX JASON:200:SALES
300 YU CHAO:300:SINA PRODUCT DEVELOPMENT
400 SANJAY GUPTA:400:SUPPORT
500 NISHA SINGH:500:SALES
1000 YU JUN:1000:PEKING UNIVERSITY EECS
[www.linuxidc.com @linux source]$tr A-Z a-z <sinadept.txt
100 harry potter:100:magic school
200 alex jason:200:sales
300 yu chao:300:sina product development
400 sanjay gupta:400:support
500 nisha singh:500:sales
1000 yu jun:1000:peking university eecs
[www.linuxidc.com @linux source]$

如果文件過大的話處理起來很方便,如果你會VIM或者是其他工具的話,也有很好的方法用來處理同樣的問題。

Copyright © Linux教程網 All Rights Reserved