LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-23-2006, 08:36 PM   #1
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 249

Rep: Reputation: 30
xargs multiple ./{} usage


I'm trying to process a bunch of text files in a directory, and replace the word "Music" with "music" (simple case change). I can use sed to do the change, but I do not know how to have them output/overwrite the original files with original filenames. How can I use multiple ./{} with xargs?

Here's what I have thus far:
Code:
find . -maxdepth 1 -name \*.m3u | xargs -i -t cat ./{} | sed "s/Music/music/g" > ./{}
 
Old 02-23-2006, 08:51 PM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Use the "-i" option. This will edit them inplace.
find ./ -maxdepth 1 -name "*.m3u" -print0 | xargs -0 sed -i 's/Music/music/g'

Another option is to use a for loop:
for file in *.m3u; do
sed 's/Music/music/g' $file >new_$file
done

This won't work:
sed 's/Music/music/g' $file >$file

It will erase your original before reading it.
So you either have to save the output to another file, or use the -i option.

I added the -print0 and -0 options to handle the case where a filename contains whitespace.
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs and my own script harmster Linux - Software 4 05-07-2005 10:35 AM
error with find . | xargs cbonar Linux - Newbie 7 12-09-2004 11:22 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
xargs question reitzell Linux - Newbie 4 07-04-2004 02:36 AM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 10:04 PM


All times are GMT -5. The time now is 11:28 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration