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

need help for sed

Reply to Message Icon

Original Message
Name: jds
Date: December 4, 2007 at 18:21:39 Pacific
Subject: need help for sed
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."


Report Offensive Message For Removal


Response Number 1
Name: jds
Date: December 4, 2007 at 18:55:47 Pacific
Subject: need help for sed
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: radoulov
Date: December 9, 2007 at 03:44:45 Pacific
Subject: need help for sed
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: jds
Date: December 15, 2007 at 01:49:49 Pacific
Subject: need help for sed
Reply: (edit)

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


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

Comments:

 


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