日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux shell之paste合并文件和找到匹配的文件里面替换内容(find和-exec或xargs组合)

發布時間:2023/12/4 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux shell之paste合并文件和找到匹配的文件里面替换内容(find和-exec或xargs组合) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1?問題

1)合并2個文件,這里用paste命令

2)找到匹配的文件里面替換內容,這里用find 和 -exec或xargs命令組合

?

?

?

?

2 實現

1)合并2個文件,這里用paste命令,我們在paste后面加參數-d 然后加" ",表示文件之間內容隔著空格,“,”表示文件之間內容隔著內容

cat 1.txt 1 2 3 4 5 6 cat 2.txt chenyu chengongyu hello paste 1.txt 2.txt -d ',' 1,chenyu 2,chengongyu 3,hello 4, 5, 6, paste 1.txt 2.txt -d ' ' 1 chenyu 2 chengongyu 3 hello 4 5 6

2)把當前目錄下的cpp文件里的chenyu替換成hello(find和-exec組合)

cat 1.cpp chenyu chengongyu chenzixuan chenyu cat 2.cpp chenyu chenzixuan chengongyu chenyu cat 3.cpp chenyu chencaifeng chengongyu cat 4.cpp chenyu chengong chenyu chencaifengfind . -name "*.cpp" -exec sed -i 's/chenyu/hello/' {} \;cat 1.cpp 2.cpp 3.cpp 4.cpp hello chengongyu chenzixuan hello hello chenzixuan chengongyu hello hello chencaifeng chengongyu hello chengong hello chencaifeng

3)把當前目錄下的cpp文件里的hello替換成chenyu(find和xargs組合)

find . -name "*.cpp" | xargs sed -i 's/hello/chenyu/'cat 1.cpp 2.cpp 3.cpp 4.cpp chenyu chengongyu chenzixuan chenyu chenyu chenzixuan chengongyu chenyu chenyu chencaifeng chengongyu chenyu chengong chenyu chencaifeng

?

?

?

3?要注意的地方

1)使用sed命令的時候要記得參數加-i,然后后面一般是's/pattern/replace_str/'? 而不是's/pattern/replace_str'? 忘記最后一個左斜杠會報錯?

2)我們使用-exec的時候一般模式是下面的

-exec commond {} \;? ?這個{}和\;不能挨著一起,同時\;不能分開,比如\ ;也會有問題

總結

以上是生活随笔為你收集整理的linux shell之paste合并文件和找到匹配的文件里面替换内容(find和-exec或xargs组合)的全部內容,希望文章能夠幫你解決所遇到的問題。

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