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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search and Replace command

Reply to Message Icon

Name: roneo
Date: February 6, 2002 at 15:51:24 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: February 7, 2002 at 07:37:27 Pacific
Reply:

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


0

Response Number 2
Name: Yeheya Ansari
Date: February 9, 2002 at 23:18:37 Pacific
Reply:

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


0

Response Number 3
Name: Ritesh
Date: June 24, 2002 at 10:24:45 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Search and Replace command

Help search and replace www.computing.net/answers/unix/help-search-and-replace/6886.html

Search and replace string in files www.computing.net/answers/unix/search-and-replace-string-in-files/7857.html

Unix - Search and replace www.computing.net/answers/unix/unix-search-and-replace/6775.html