簡體   English   中英

Shell命令xargs和sed不起作用

[英]Shell command xargs & sed doesn't work

我只想批量修改文件的后綴,但這是行不通的! 我使用的命令行如下:

ls *html | xargs  -I{}  echo "\`echo {} |  sed 's/html/css/g'\`"

但是,當我只使用ls *html ,它顯示:

file1.html  file2.html  file3.html  file4.html  file5.html

二手ls *html | sed 's/html/css/g' ls *html | sed 's/html/css/g' ,如我所料! 像這樣:

file1.css file2.css file3.css file4.css file5.css

我在Mac OS上工作。 有人可以給我一些建議嗎? 提前謝謝。

因為反引號用雙引號引起來,所以它由外殼程序立即執行,而不是由每個文件上的xargs執行。

結果與

ls *html | xargs -I{} echo "{}"

但是,如果使用單引號,則會遇到其他麻煩。 您最終不得不做這樣的事情:

ls *html | xargs -I{} sh -c 'echo `echo {} | sed '\''s/html/css/g'\''`'

但這真是一團糟,我們甚至還沒有真正的重命名。

使用循環會更好一些:

for file in *html; do
  newname=${file%html}css
  mv "$file" "$newname"
done

使用GNU並行:

ls *html | parallel echo before {} after {.}.css

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM