With sed replaced special character is printed twice, why?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
With sed replaced special character is printed twice, why?

Dear all,
I was wondering If you could help me out.
I Am using a batch script to midfy some text files.

Input:
Code:
912856
912857
912904

Amongst others I use this line:
Code:
REM I want to replace all lines that start with a 6-digit Number with a ftp command "get" followed by a path and the 6-digit number.
call N:\Tools\sed.exe "s/\([0-9][0-9][0-9][0-9][0-9][0-9]\)/     \"get \/LADIDADI\/ds01005\/\1\" ^/"

Output:

Code:
     "get /LADIDADI/ds01005/912856" \^^
     "get /LADIDADI/ds01005/912857" \^^
     "get /LADIDADI/ds01005/912904" \^^

This works somehow but the special character "^" is printed twice and I do not know how to correct that.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-14-2019 at 02:13 PM.. Reason: Added CODE tags.
# 2  
Welcome to the forum.


I can't reproduce the behaviour that you show. With "sed (GNU sed) 4.5" it just prints one caret ^ , not an escaped plus an unescaped caret, which I presume is exactly what you want.



Is that a cygwin (or similar) on a windows system? I don't know the peculiarities of that implementation... any chance to deploy another version / tool?

Last edited by RudiC; 03-15-2019 at 04:52 AM..
This User Gave Thanks to RudiC For This Post:
# 3  
Thanks for the warm welcome

Thanks RudiC for the warm welcome.

I use the unix tool set from sourceforge.net.
Do you have any recommendation for a unix tool set for windows?
cheers,
Michael
# 4  
Hi Michael,

as far as I remember from my Windows-Times ages before, there are

UnxUtils
UnxUtils download | SourceForge.net

CygWin
Cygwin

Maybe there are different Options now. Ask your friend google.

Regards,
stomp

Last edited by stomp; 03-15-2019 at 07:27 AM..
This User Gave Thanks to stomp For This Post:
# 5  
Welcome Michael Smilie
Yes, it must be a problem that is specific to your environment.
Perhaps it treats a ^ character special? Try to escape it: \^ or ^^

You better chose another delimiter, then the / character does not conflict:
Code:
sed "s#\([0-9][0-9][0-9][0-9][0-9][0-9]\)#     \"get /LADIDADI/ds01005/\1\" \^#"

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Thanks madeInGermany

Thanks, but I still get the same result. Smilie
What I try to do is to create an FTP Batch File that transfers only a limited list of folders.
I use WinScp for the connection and now I fail in editing the "get" commands for each line which I need to end with the ^ character so the next line is interpreted.
I added two images. one shows the files I want to edit and the the is the result of my sed command.

Any help appreciated.
cheers,
Michael
With sed replaced special character is printed twice, why?-before_getfiles_ftpbatpng
With sed replaced special character is printed twice, why?-after_getfiles_ftppng
# 7  
If you can't change tools, I'm afraid you have to experiment. Does that duplication happen to other characters as well? Does it happen in the last position only? Is it an output artifact only, perhaps? Can you remove the last character by an additional sed command?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to add special character (')

I have a file (input) which contains are below. Member Analytics Engine Enterprise Manager Dev Tutorial I want to change contains as below by using sed command 'Member Analytics Engine'; 'Enterprise Manager'; 'Dev Tutorial'; First, I tried to add (') on every first line by using sed... (8 Replies)
Discussion started by: anshu ranjan
8 Replies

2. Shell Programming and Scripting

sed add special character

Hi all I got test.test.test and need test.test\.test * I need the backslash before the last dot in the line I tried echo test.test.test | sed 's/\./\\./g' but it gives me test\.test\.test Thanks (7 Replies)
Discussion started by: stinkefisch
7 Replies

3. UNIX for Dummies Questions & Answers

Replacing special character with sed

Hi All, I have a text file that contains I1SP2 *=*=Y=M=D001D My requirement is to replace all occurrence of =* to =Z expected o/p is I1SP2 *=Z=Y=M=D001D I have tried with sed 's/=*/=Z/g' file sed 's!\=*!\=Z/g' file sed 's!\=*!\=Z!g' file sed 's!\=\*!\=Z!g' file but its not... (3 Replies)
Discussion started by: gotamp
3 Replies

4. Shell Programming and Scripting

How to replace special character using sed?

How can I replace the follong text including to number 7000? cat tmp0.txt Winston (UK) Wong I would the 7000 to replace Winston (UK) Wong. I fail with method below: sed ' s /Winston\(UK\)Wong/7000 tmp0.txt' (1 Reply)
Discussion started by: vivien_chu
1 Replies

5. Shell Programming and Scripting

how to replace the special character with another using SED

I have the replace the pattern in the file , ); to ); Could someone please help me to get this command. (2 Replies)
Discussion started by: mohan.bit
2 Replies

6. Shell Programming and Scripting

sed special character replace

I need to do the following: text in the format of: ADDRESS=abcd123:1111 - abcd123:1111 is different on every system. replace with: ADDRESS=localhost:2222 sed 's/ADDRESS=<What do I use here?>/ADDRESS=localhost:2222/g' Everything I've tried ends up with: ... (3 Replies)
Discussion started by: toor13
3 Replies

7. Shell Programming and Scripting

Decode %s Special Character in Sed

Greetings, I am doing something that I don't know if it is possible... I have a file with a line looks like this: <%s \n%s / %s \n%s \n> and I am trying to replace this line with <%s \n%s \n%s / %s \n%s \n> in Shell script with sed command... StringToReplace='%s \n%s / %s \n%s \n'... (2 Replies)
Discussion started by: wasabihowdi
2 Replies

8. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies

9. Shell Programming and Scripting

Sed-Special character replacement

Hi I want to replace ./testsed.ksh with testsed.ksh ./ is to be removed scriptnm=`sed -e 's/\.///' $0 does not work Please help (3 Replies)
Discussion started by: usshell
3 Replies

10. Shell Programming and Scripting

sed and special character in data

I have a script that is reading an existing report, pulling out the customer code, then tacking on the customer name from another file and replacing the existing customer code with the new field. This was written for me by someone else. I'm not real familiar with sed. The data is getting into... (3 Replies)
Discussion started by: MizzGail
3 Replies

Featured Tech Videos