Computing.Net > Forums > Unix > need help for sed

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.

need help for sed

Reply to Message Icon

Name: jds
Date: December 4, 2007 at 18:21:39 Pacific
OS: windowsXP
CPU/Ram: petium III/ram 256
Comment:

Hi All,
I found this post from a few years ago.
My question is Can I do it a litlle bit further:
I wan to find out the first letter start with P and replace text( numbers) from 23rd to 26th, 43 to 46, and 63 to 66 with ****. How can I do it using a sed or some other better way.

Thanks in advance
I copied the previous post bellow here
"Name: Matt
Date: March 11, 2004 at 04:02:01 Pacific
Subject: spefic SED replace command
HI all
I need to replace the 23rd character on all lines beginning with P , with a blank character. Ive heard that the SED command is the best option, Can anybody help with the specific command line that would perform this operation.
Name: aigles
Date: March 11, 2004 at 06:03:16 Pacific
Subject: spefic SED replace command

Reply:
The solution with sed :
sed 's/^\(P.\{21\}\)./\1 /' input_file
Jean-Pierre."



Sponsored Link
Ads by Google

Response Number 1
Name: jds
Date: December 4, 2007 at 18:55:47 Pacific
Reply:

correction:
I wan to find out the first letter start with P and replace text( numbers) from 23rd to 26th, 143 to 146, and 263 to 266 with ****. How can I do it using a sed or some other better way.

It seems not allow me to parse the 263 to 266 one
my approch is like this
sed 's/^\(P.\{23\}\)[0-9][0-9][0-9][0-9]/\1****/' tmp |sed 's/^\(P.\{243\}\)[0-9][0-9][0-9][0-9]/\1****/' | sed 's/^\(P.\{263\}\)[0-9][0-9][0-9][0-9]/\1****/' | >tmp1
I got this error:
sed: Function s/^\(P.\{263\}\)[0-9][0-9][0-9][0-9]/\1****/ cannot be parsed.
even I split it into 2 line still got same error

Please help


0

Response Number 2
Name: radoulov
Date: December 9, 2007 at 03:44:45 Pacific
Reply:

Post a sample from your input and example of the expected output.


0

Response Number 3
Name: jds
Date: December 15, 2007 at 01:49:49 Pacific
Reply:

My file has dozens lines and each line starts with 01~ has over 400 characters, other lines start with something else I don’t want to touch
I want to replace the line start with 01~ for the position 23 to 26, 143 to 146, and 263 to 266 with ****. if it is number ( if it is blank then no change)
Some thing like this:
01~12345……2222………… …………4444…………
02~sdfsdfasdfasd
I want to change to
01~12345……****………… …………****…………
02~sdfsdfasdfasd


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Variable Variables script to see what softwa...



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: need help for sed

need help on SED script www.computing.net/answers/unix/need-help-on-sed-script/7487.html

need help for sed www.computing.net/answers/unix/need-help-for-sed/8028.html

help with a sed function www.computing.net/answers/unix/help-with-a-sed-function/4297.html