Hi,
Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command.
sed 's/^\(.\{289\}\)-/\1O/' filename
sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed.
Thanks in Advance
Sara
Hi,
Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command.
sed 's/^\(.\{289\}\)-/\1O/' filename
sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed.
Thanks in Advance
Sara
I think sed has a limitation, you cannot specify more than 255 in curly braces "\{ \}", then you will get the following error:-
cannot be parsed.
Is there any alternative for this issue?
try:
sed 's/^\(.\{200\}.\{89\}\)-/\1O/' filename
It worked fine .
Great! Thanks alot.
---------- Post updated at 04:34 PM ---------- Previous update was at 04:30 PM ----------
Is there way to write that into new file?
I tried with
sed 's/^\(.\{200\}.\{89\}\)-/\1O/' file1 > file2
but i got the content in the file2 with old data of file1.
Yes, you have to break the number 289=255+34:-
sed 's/^\(.\{255\}.\{34\}\)-/\1O/' infile
EDIT: make sure you have a - sign at this position, otherwise the replace will not happen.
I got it Thanks!.
for only the lines that got updated:
sed -n 's/^\(.\{200\}.\{89\}\)-/\1O/p' filename
Hi bipinajith,
i tried to use your code to replace the character at certain position. but it is not doing as desired, can u please assit
0979BB0979B I want to replace the 5th and 10th position.
Also, how can we do it in sed if we have to A-1, B-2, C-3, D-4 in different fields..
Currently i m using this code - any help will be appreciated..
cat b.txt | sed -e 's/^\(.\{200\}.\{153\}\)B/\1X/' > xx.txt
Replacing 5th & 10th position with C & D:-
echo 0979BB0979B | sed 's/^\(.\{5\}\)B/\1C/; s/^\(.\{10\}\)B/\1D/'
0979BC0979D