Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search And Replace

Status
Not open for further replies.

roneo

Programmer
Feb 6, 2002
4
US
I am trying to write a Unix Shell Script command that would clean up the XML files by eliminating spaces between the nodes...example:
<PERSON>
<NAME>James</NAME>
</PERSON>

the command has to make:
<PERSON><NAME>James</NAME></PERSON>

anyone has clues ???
Thanks
 
If you want to get rid of all newlines and all spaces, you can use &quot;tr&quot;. For example:

tr -d '\012' < file > file1
tr -d '\040' < file1 > file2

Produces a file2 with no spaces or newlines. But this doesn't work if you have spaces in your parameters.

You might want something like:

tr -d '\012' < file > file1 #remove newlines
tr -s '\040' < file1 > file2 #remove multiple spaces
echo '\012' >> file2 #add 1 newline at end
sed -e &quot;s/ </</g&quot; file2 > file3 #replace &quot; <&quot; with &quot;<&quot;

Hope that helps!
 
That will probably work, thanks. It actually should scan and edit xml files in a specified directory, then copy them into another dir preserving all the subderictory structure...something like this, but only it should work lol

sed -e &quot;s/\s+|^&//g&quot; c:\XMLCleanup\*.xml > c:\XMLFinal\*.xml

i knew it would be tricky lol I have done this long time ago, I think i captured the ls output and then grabbed names and tested them...grrrr if u have example of this please send. thanks.
 
If you have a number of files to deal with, you can put them in a for loop and process them 1 at a time:

CURDIR=/XMLCleanup
NEWDIR=/XMLFinal

for FILE in $CURDIR/*.xml
do
{do your file processing on $FILE,
with output to $NEWDIR/$FILE)
done

Is that what you're looking for?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top