Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 02-23-2006, 08:36 PM   #1
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:
find . -maxdepth 1 -name \*.m3u | xargs -i -t cat ./{} | sed "s/Music/music/g" > ./{}
Old 02-23-2006, 08:51 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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

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.


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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:42 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