Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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."

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 errorPlease help

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

![]() |
Variable Variables
|
script to see what softwa...
|

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