Computing.Net > Forums > Unix > Search and Replace command

Search and Replace command

Reply to Message Icon

Original Message
Name: roneo
Date: February 6, 2002 at 15:51:24 Pacific
Subject: Search and Replace command
Comment:

I am trying to write a Unix Shell Script command that would clean up the XML files by eliminating spaces between the nodes...example:

James


the command has to make:
James

anyone has clues ???
Thanks


Report Offensive Message For Removal


Response Number 1
Name: James Boothe
Date: February 7, 2002 at 07:37:27 Pacific
Subject: Search and Replace command
Reply: (edit)

I'm not sure of your requirements, but it looks like you want to eliminate blank lines. You can eliminate null lines (entirely empty) with either:

grep -v '^$' myfile > mynewfile
awk 'length!=0' myfile > mynewfile

Or if you want to eliminate both the null lines and lines that contain only white space, you could use:

awk 'NF>0' myfile > mynewfile


Report Offensive Follow Up For Removal

Response Number 2
Name: Yeheya Ansari
Date: February 9, 2002 at 23:18:37 Pacific
Subject: Search and Replace command
Reply: (edit)

Hi!
If u want to remove space, u can use the following command:-
sed "s/ *//g"

i.e sed "s/*//g" {ur input file}
This will output the required file on screen.
U can redirect this to any file using >

For ex: sed "s/ *//g" myxml >reqxml

If u want to remove spaces or tabs, then u can use this (Pls try following...I am not sure at this moment for this)

sed "s/[ ]*//g" {Input File}

i.e sed "s/[]*//g" {input file}

I hope this will server u


Report Offensive Follow Up For Removal

Response Number 3
Name: Ritesh
Date: June 24, 2002 at 10:24:45 Pacific
Subject: Search and Replace command
Reply: (edit)

I think you have to read the XML document using XML processor/parser and then write it again.
I think that using unix commands will not be that useful.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Search and Replace command

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software