Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-23-2007, 07:12 AM   #1
LQ Newbie
Registered: Oct 2007
Posts: 1

Rep: Reputation: 0
Xargs -i problems.


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!


Anders, Gothenburg
Old 10-24-2007, 04:43 PM   #2
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 755

Rep: Reputation: 144Reputation: 144
I think I would do it this way:

for f in invoice*; do mv $f $(echo $f|sed s/invoice/paid/); done
Old 10-25-2007, 04:23 AM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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:
for f in invoice*; do mv "$f" "${f/invoice/paid}"; done


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
`wc`, `xargs` h/w Programming 11 09-30-2007 05:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 05:26 PM
Xargs: Missing quote mellowjen Programming 5 02-27-2007 06:29 PM
xargs and my own script harmster Linux - Software 4 05-07-2005 11:35 AM
xargs question reitzell Linux - Newbie 4 07-04-2004 03:36 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration