Hi,
I want to replace a character in every line in the file
say the file looks like this
SOBO20060830094122140014541834 WENP0414541835 ]
SOBO20060830094121140014541834 WENP0414541835
SOBO20060830094121140014541834 WENP0414541835
I want to replace the blue 00 by TS.
sed 's/^\(.\{20\}\)00\(.*\)/\1TS\2/' myFile.txt
Hey It works.
Thank you very much.
But could you please explain the command .
sed 's/^\(.\{20\}\)00\(.*\)/\1TS\2/'
What is that 1 and 2 [marked in blue ] for ?
let me color-code it for ya with matching colors:
sed 's/^\(.\{20\}\)00\(.*\)/\1TS\2/' myFile.txt
Sorry have not understood yet .
to quote 'man sed':
2 s/regular expression/replacement/flags
____________________________________________________________
Substitute the replacement string for
instances of the regular expression in the
pattern space. Any character other than
backslash or newline can be used instead of a
slash to delimit the RE and the replacement.
Within the RE and the replacement, the RE del-
imiter itself can be used as a literal charac-
ter if it is preceded by a backslash.
____________________________________________________________
An ampersand (&) appearing in the replacement
will be replaced by the string matching the
RE. The special meaning of & in this context
can be suppressed by preceding it by
backslash. The characters \n, where n is a
digit, will be replaced by the text matched by
the corresponding backreference expression.
For each backslash (\) encountered in scanning
replacement from beginning to end, the follow-
ing character loses its special meaning (if
any). It is unspecified what special meaning
is given to any character other than &, \ or
digits.