Search and replace in variables

I've got an app (lndir) that expects a unix formated path instead of Windows ones.
Just fixing the path I can easily do using sed, but I don't know how to use the fixed path in script.

Input:
{sourcepath} and {destpath}

that's transformed using [sed "s#([a-zA-z]):#/cygdrive/\1#" | sed "s#\#/#g"] into /cygdrive/c/source

Output (as it should be):
lndir /cygdrive/c/source /cygdrive/c/target

Would be nice if anyone could help me getting the transformed form into a variable so I can use it in the lndir command. Thx in advance

There are a few ways you could do this. I think the best one would be to use some VBScript (or JavaScript, Perl, etc.) glue to convert the paths and then run the program.

See this post for some pointers & links about how the script could be called from Opus:

[Is there a way to cut paths like this in a command?)

Shout if you need help writing the script.

shout
I've never written any VBScript or similar. Kinda made it work with batch but it's pretty ugly. Maybe you've got an idea to make it nicer?

Below is the batch code I'm calling with "lnd.bat {filepath} {destpath} {file}":

@echo off set source=%1 set dest=%2 if /i %source:~1,1% == %dest:~1,1% GOTO createlink echo ERROR: Source and target drive must be identical. pause exit :createlink echo %1 | sed "s#\([a-zA-z]\):#/cygdrive/\1#" | sed "s#\\\#/#g" > d:\tmp\tmpFile set /p cygsourcepath= < d:\tmp\tmpFile cd %2 mkdir %3 cd %3 cd > d:\tmp\tmpFile set /p destpath= < d:\tmp\tmpFile echo %destpath% | sed "s#\([a-zA-z]\):#/cygdrive/\1#" | sed "s#\\\#/#g" > d:\tmp\tmpFile set /p cygdestpath= < d:\tmp\tmpFile lndir %cygsourcepath% "%cygdestpath%"

Can you give an example of the complete input & output-strings ?!

Nice batch! Did not know "sed" before, but found it in my
cmd-tool collection.. o) That is one real diehard-unix-tool.. o)

Don't know if you need to use sed, for replacing operations dos-batch
can help to.

set source=%1
set source=%source::=/%
set source=%source:=/%

..would replace all occurrences of ":" and "" with "/" -> unix-style.
c:\testfolder\testfile -> c/testfolder/testfile

..but I don't know if that's all you need, I admit, i don't get your sed-params.. o)

regards,
rob.

what that script does is

  1. get called with "lnd.bat {filepath} {destpath} {file}", eg. "lnd.bat c:\source c:\target source")
  2. compare the drive letters as lndir will only work on the same partition
  3. replace "X:" with "/cygdrive/x" and every "" with "/" in sourcepath (this transform c:\test into /cygdrive/c/test)
  4. put that transformed path in a variable cygsourcepath
  5. create a directory with the source directories name in destination folder ("cd c:\target", "mkdir source")
  6. repeat 2 and 3 for destination
  7. run lndir (lndir /cygdrive/c/source/ /cygdrive/c/target)