Xargs -i problems.
Howdy!
I had a few files named nameNUMBER (like invoice0102 and so on) which I wanted to rename with a new name but keep the number. I first tried and xargs command that I didn't get to work so I fixed it "by hand" to solve my problem but then went back to the xargs idea to see if I could find out how it works. I fail to get it to work with xargs. My try was: find . -type f | xargs -iinvoice## mv invoice## paid## The shell tries to do (verified with an echo infront of the mv): mv invoice0102 paid## mv invoice0103 paid## ... and so on. So it works like intended apart from the fact that it does not replace the second ##. How can I get xargs to replace both ##? Thanks a lot for any help! Regards. Anders, Gothenburg Sweden. |
I think I would do it this way:
for f in invoice*; do mv $f $(echo $f|sed s/invoice/paid/); done |
better than calling sed for every line of input, which is very slow when there are a lot of files, you can use bash's internal string substitution. It is also good idea to quote the parameters to mv:
Code:
for f in invoice*; do mv "$f" "${f/invoice/paid}"; done |
All times are GMT -5. The time now is 03:02 PM. |