With sed replaced special character is printed twice, why?


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
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; 1 Week Ago at 01:13 PM.. Reason: Added CODE tags.
# 2  
Old 1 Week Ago
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; 1 Week Ago at 03:52 AM..
This User Gave Thanks to RudiC For This Post:
SIEMI (1 Week Ago)
# 3  
Old 1 Week Ago
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  
Old 1 Week Ago
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; 1 Week Ago at 06:27 AM..
This User Gave Thanks to stomp For This Post:
SIEMI (1 Week Ago)
# 5  
Old 1 Week Ago
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:
SIEMI (1 Week Ago)
# 6  
Old 1 Week Ago
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_ftp-bat-png
With sed replaced special character is printed twice, why?-after_getfiles_ftp-png
# 7  
Old 1 Week Ago
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 to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
sed command to add special character (') anshu ranjan Shell Programming and Scripting 8 09-08-2016 04:44 PM
sed add special character stinkefisch Shell Programming and Scripting 7 09-01-2016 09:37 AM
Replacing special character with sed gotamp UNIX for Dummies Questions & Answers 3 03-08-2016 11:16 AM
How to replace special character using sed? vivien_chu Shell Programming and Scripting 1 10-15-2012 09:31 AM
How to substitute variable in sed for special character? vinothsekark Shell Programming and Scripting 9 04-29-2012 06:39 AM
how to replace the special character with another using SED mohan.bit Shell Programming and Scripting 2 02-01-2011 05:59 PM
sed special character replace toor13 Shell Programming and Scripting 3 01-20-2011 11:57 AM
How to print range of lines using sed when pattern has special character "[" nehashine Shell Programming and Scripting 3 05-06-2010 04:13 AM
Decode %s Special Character in Sed wasabihowdi Shell Programming and Scripting 2 02-15-2010 05:19 AM
Deleteing one character after an special character mohsin.quazi Shell Programming and Scripting 1 10-20-2009 04:27 PM
Special Character SED/AWK removal Raggedranger333 Shell Programming and Scripting 6 02-26-2009 03:07 PM
special character tostay2003 Shell Programming and Scripting 4 01-06-2009 08:07 PM
Sed-Special character replacement usshell Shell Programming and Scripting 3 05-22-2008 10:06 AM
sed and special character in data MizzGail Shell Programming and Scripting 3 01-23-2008 02:45 PM
Special characters getting replaced by &Pound in Unix Environment kaushik05 UNIX for Advanced & Expert Users 0 09-23-2005 01:10 AM