LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-18-2014, 05:51 PM   #1
AnalBeard
Member
 
Registered: Aug 2010
Distribution: Ubuntu 13.04 Server
Posts: 31

Rep: Reputation: 0
some help with xargs please


Ok, I'm trying to run a command to find all files by a certain name under a particular subdirectory and then match and remove a line in them (they're just xml files). I chucked together the command below which worked fine on the simple test directory I assembled in ~/, however as soon as I run it on the actual files I want altered, it's not exactly successful.

Code:
find . -name movie.xml | xargs -0 sed -i.bak '/<set>/d'
Obviously this is run from the parent directory of those which contain the xml file, and they're never found more than 1 subdirectory below this. The command is supposed to match any lines starting with the <set> tag (whether indented or not) and then remove them. If I run the command it appears to list all the matches produced by find, however it doesn't seem to do anything with them (aside from produce the .bak). Where am I going wrong?
 
Old 02-18-2014, 07:03 PM   #2
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You will also need the '-print0' option for find. This prints null characters instead of newlines and is compatible with the '-0' option of xargs.
 
Old 02-19-2014, 03:27 AM   #3
AnalBeard
Member
 
Registered: Aug 2010
Distribution: Ubuntu 13.04 Server
Posts: 31

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by metaschima View Post
You will also need the '-print0' option for find. This prints null characters instead of newlines and is compatible with the '-0' option of xargs.
That did the trick - thanks very much!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 07:26 PM
How to use xargs within xargs ? anindyameister Linux - Newbie 1 05-15-2013 05:01 AM
Using xargs SBN Linux - General 2 04-07-2008 07:44 PM
`wc`, `xargs` h/w Programming 11 09-30-2007 04:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 04:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:54 PM.

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