Computing.Net > Forums > Unix > Help search and replace

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.

Help search and replace

Reply to Message Icon

Name: gpatel
Date: April 29, 2005 at 06:26:53 Pacific
OS: UNIX
CPU/Ram: 512
Comment:

I am working w/ this huge matrix file. Now in this matrix file 2nd
column is strings. lets say its contain red, blue, black. now i can
not load this file in matlab. so i wanted to change red to 1 blue to 2 and
black to 3. Is there any eaiser way instand of find an replace. As i
said this is a huge file so it will take lot of time if i do search
and replace. can someone please help me write a scipts or something.
i am using unix so you could also use unix command.
thanks a lot
Gpatel

thanks,
Gaurav



Sponsored Link
Ads by Google

Response Number 1
Name: gpatel
Date: April 29, 2005 at 08:32:16 Pacific
Reply:

i have got this a little bit

this is what i found out in unix using sed

sed -e 's/red/1/g' filename.txt > filename.new.txt

now someone please help me with If and else statement

thanks,
Gaurav


0

Response Number 2
Name: nails
Date: April 29, 2005 at 08:47:21 Pacific
Reply:

What do you need an if statement for:

sed -e 's/red/1/g' -e 's/blue/2/g' -e 's/black/3/g'


0

Response Number 3
Name: Luke Chi
Date: April 29, 2005 at 09:04:39 Pacific
Reply:

Not sure about your file format. Assuming:

column_value1 column_value_2 column_value3
...

Script:

sed -e 's/ red / 1 /' -e 's/ blue / 2 /' -e 's/ black / 3 /' <your file>

Luke Chi


0

Response Number 4
Name: gpatel
Date: April 29, 2005 at 10:36:49 Pacific
Reply:

sorry, this is the first time i am using UNIX and i am loving it. I will be doing this for rest of my life. so need to learn fast. thanks a lot guys.
i needed a script b/c i do this more than one time. i need to load all the data in matlab and simulate it. but this will work
thanks AGAIN.


thanks,
Gaurav


0

Response Number 5
Name: gpatel
Date: April 29, 2005 at 10:38:52 Pacific
Reply:

P.S. I was talking about if and elst statements b/c sometimes there is no red in file. or there is no blue. again thanks a lot for your help

thanks,
Gaurav


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






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: Help search and replace

Search And Replace With Sed www.computing.net/answers/unix/search-and-replace-with-sed/3845.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