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:

912856
912857
912904

Amongst others I use this line:

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:

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

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?

1 Like

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

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

1 Like

Welcome Michael :slight_smile:
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:

sed "s#\([0-9][0-9][0-9][0-9][0-9][0-9]\)#     \"get /LADIDADI/ds01005/\1\" \^#"
1 Like

Thanks, but I still get the same result. :confused:
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

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?

For the record: GNU sed is available on Windows(UnxUtils contains GNU sed 4.0.7) and works fine with that problem. For downloads see links above.

sed -r "s#([0-9]{6})#     \"get /LADIDADI/ds01005/\1\" ^#" test.txt
1 Like

Maybe something else generates a trailing ^ ?
Try to omit it in the sed:

sed "s#\([0-9][0-9][0-9][0-9][0-9][0-9]\)#     \"get /LADIDADI/ds01005/\1\" #"
1 Like

Hi SIEMI..

As stomp has already quoted there is also CygWin.

It is a reliable *NIX-alike terminal _emulator_ for want of a better word.
It has a very large subset of tools/utilities that we expect of the UNIX environment.
AFAIK the tools/utilities are GNU compatible.
The terminal is called 'mintty' and also has a very large subset of terminal escape codes too.

There is an excellent package list for it though for anything not installed by default:

Cygwin Package List

However there are foibles.

  • It IS SLOW doing tasks compared to its REAL counterparts. It can be debilitatingly slow at times.
  • Some tools/utilities are not available from a DEFAULT install, bc, dc and hexdump were three of those but may well be implemented now.
  • I always feel Windows itself gets in the way as in writing to STDOUT seems very slow compared to a REAL *NIX environment like OSX 10.14.x, or Linux.
  • If you like attacking the HW, then don't expect an immediate response. '/dev/dsp' IS available but if you call it there could be up to a second or more delay before it starts. This is what I mean about Windows getting in the way.
1 Like