LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


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

Rep: Reputation: 0
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.
 
Old 10-24-2007, 03:43 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
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, 03:23 AM   #3
matthewg42
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:
Code:
for f in invoice*; do mv "$f" "${f/invoice/paid}"; done
 
  


Reply



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 04:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 04:26 PM
Xargs: Missing quote mellowjen Programming 5 02-27-2007 05:29 PM
xargs and my own script harmster Linux - Software 4 05-07-2005 10:35 AM
xargs question reitzell Linux - Newbie 4 07-04-2004 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:42 AM.

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