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

Jean-Pierre:
Good solution. Can you explain what you are doing for the benefit of us non-sed experts?
Thanks!
Nails

i'm like in awe of Jean-Pierre's solution. I had to
man, info and browse to understand it. i'd like to try to explain so I will really learn it.
The \ are shell escapes (except \1),so consider
sed 's/^(P.{21})./\1 /' input_file(reg_exp) is a "grouping" of a regular expression pattern match and \1 is the value of match 1 - match 2 would be the 2nd set of parens, if there were any.
r{n} is an "interval expression", so the preceding regular expression r is repeated n times. In this case: .{21} is 21 of any character.
^P.{21} is the 1st 22 characters of lines beginning with P
Note the "." in })./\1 - this is the 23rd character- it is not in the () grouping.
So sed 's/^\(P.\{21\}\)./\1 /' input_file says replace the 1st 23 characters of lines that start "P" with the 1st 22 characters + space
very neat

correction:
in sed 's/^\(P.\{21\}\)./\1 /' input_file
\ are not "shell escapes", they are "sed escapes" so that sed will recognize them as special characters, e.g.:
echo ab{cd|sed 's/{//' -> abcd

![]() |
![]() |
![]() |

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