sed find and replace command not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed find and replace command not working
# 1  
Old 11-30-2012
Java sed find and replace command not working

Hi,
Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command.
Code:
sed 's/^\(.\{289\}\)-/\1O/' filename
 
sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed.

Thanks in Advance
Sara

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 12-01-2012 at 10:51 AM.. Reason: Code tags
# 2  
Old 11-30-2012
I think sed has a limitation, you cannot specify more than 255 in curly braces "\{ \}", then you will get the following error:-
Code:
cannot be parsed.

This User Gave Thanks to Yoda For This Post:
# 3  
Old 11-30-2012
Java

Is there any alternative for this issue?
# 4  
Old 11-30-2012
try:
Code:
sed 's/^\(.\{200\}.\{89\}\)-/\1O/' filename

This User Gave Thanks to rdrtx1 For This Post:
# 5  
Old 11-30-2012
It worked fine .
Great! Thanks alot.Smilie

---------- 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.

Last edited by radoulov; 12-03-2012 at 11:20 AM..
# 6  
Old 11-30-2012
Yes, you have to break the number 289=255+34:-
Code:
sed 's/^\(.\{255\}.\{34\}\)-/\1O/' infile

EDIT: make sure you have a - sign at this position, otherwise the replace will not happen.

Last edited by Yoda; 11-30-2012 at 05:42 PM..
This User Gave Thanks to Yoda For This Post:
# 7  
Old 11-30-2012
Java

I got it Thanks!.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed command to replace "|" with ^ for all *.dat files in a folder not working

I am trying to use the below sed command to replace all "|" to ^, in a folder had 50 dat files. when i tried with 1 file it worked but when i tried with wild card, is not working. sed -i 's/"|"/\^/g' *.dat Is this the proper way to use sed command thank you very much for help. (3 Replies)
Discussion started by: cplusplus1
3 Replies

2. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

3. Shell Programming and Scripting

Search and replace is not working by sed or awk

Hi , I have one file and in this file i have one like TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;: i want to replace this line with the following line TEST1... (4 Replies)
Discussion started by: ashissau
4 Replies

4. Shell Programming and Scripting

Find and replace using sed command

The content of the file filea.txt is as follows. --------- case $HOSTNAME in aaa) DS_PARM_VALUE_SET=vsDev APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt ;; bbb) DS_PARM_VALUE_SET=vsQA... (3 Replies)
Discussion started by: kmanivan82
3 Replies

5. Shell Programming and Scripting

sed command to skip the first line during find and replace operation

Hi Gurus, I did an exhaustive search for finding the script using "sed" to exclude the first line of file during find and replace. The first line in my file is the header names. Thanks for your help.. (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

sed command to find and replace

Hello All, I need a sed command to find and replace below text in multiple files in a directory. Original Text :- "$SCRIPT_PATH/files" Replace with :- "$RESOURCE_FILE" Thank you in advance !!! Regards, Anand Shah (1 Reply)
Discussion started by: anand.shah
1 Replies

7. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

8. Shell Programming and Scripting

using sed to replace a line is not working

This is what I have this far rsh server1 "cat /home/test.txt |sed s/01-jun-2009/01-aug-2009/ |sed s/ABCD/1234/" but it is not working is there something I am doing wrong in my syntax? The file test.txt is the same on all of my 15 servers it has the same length and contents only certain... (3 Replies)
Discussion started by: deaconf19
3 Replies

9. Shell Programming and Scripting

Sed command to find, manipulate and replace a number

Hi, Im very new to the world of sed so I'm really not even sure if this is possible. What i need to do is read from a flat file and every time i see this line: VAL=123,456 I need to change 456 to 457 for every occurence of this line in the file. The numbers 123 and 456 are different for... (6 Replies)
Discussion started by: LT_2008
6 Replies

10. UNIX for Dummies Questions & Answers

how to use sed or perl command to find and replace a directory in a file

how to use sed command to find and replace a directory i have a file.. which contains lot of paths ... for eg.. file contains.. /usr/kk/rr/12345/1 /usr/kk/rr/12345/2 /usr/kk/rr/12345/3 /usr/kk/rr/12345/4 /usr/kk/rr/12345/5 /usr/kk/rr/12345/6 /usr/kk/rr/12345/7... (1 Reply)
Discussion started by: wip_vasikaran
1 Replies
Login or Register to Ask a Question