Computing.Net > Forums > Unix > sed nightmare

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

sed nightmare

Reply to Message Icon

Name: gildan2020
Date: March 20, 2003 at 05:33:11 Pacific
OS: hp-ux
CPU/Ram: multithreaded
Comment:

i hope i can explain dis correctly...
i'm currently using sed to manipulate a file containing these types of contents:
23:16:14:14:455:66:14 (figure varies for every record in dat file)

the prob is some of those figures are the same. according to de above example, is there a way to change the value of 4th field without affecting the 3rd or 7th??

thanx

gildan2020



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: March 20, 2003 at 07:09:08 Pacific
Reply:

You can use pattern matching to narrow the scope

-s'/:[0-9][0-9]$/:new_value/'

would match and change the last field.


0

Response Number 2
Name: WilliamRobertson
Date: March 20, 2003 at 15:47:31 Pacific
Reply:

You can divide up the search expression using \( \) and then refer to the matching sections in the replace expression using \1 = first section, \2 = second etc:

sed 's/\([0-9]*:\)\([0-9]*:\)\([0-9]*:\)\([0-9]*\)\(..*$\)/\1\2\3new!\5/' test.lst


0

Response Number 3
Name: gildan2020
Date: March 20, 2003 at 22:03:49 Pacific
Reply:

alright, it works!!

thanx a lot guys

gildan2020


0

Response Number 4
Name: WilliamRobertson
Date: March 20, 2003 at 23:16:11 Pacific
Reply:

This also works in vi, and the regular expression syntax is pretty much the same in Perl and JavaScript.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Fail to compare two strin... shell script help



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: sed nightmare

sed dropping last line of file www.computing.net/answers/unix/sed-dropping-last-line-of-file/5125.html

SED using special characters www.computing.net/answers/unix/sed-using-special-characters/4804.html

Increment a number using awk or sed www.computing.net/answers/unix/increment-a-number-using-awk-or-sed/6827.html