Google Answers Logo
View Question
 
Q: DOS shell Question : Path conversion from DOS to UNIX pathnames. ( Answered 3 out of 5 stars,   3 Comments )
Question  
Subject: DOS shell Question : Path conversion from DOS to UNIX pathnames.
Category: Computers > Programming
Asked by: cheekoo1-ga
List Price: $5.00
Posted: 23 Dec 2003 14:29 PST
Expires: 22 Jan 2004 14:29 PST
Question ID: 289815
I am doing 
pushd ..\..
set VARVAL=%CD%
popd 
Value of VARVAL is c:\tools\arizona\framework
I want to convert it to c:/tools/arizona/framework
Answer  
Subject: Re: DOS shell Question : Path conversion from DOS to UNIX pathnames.
Answered By: endo-ga on 23 Dec 2003 16:03 PST
Rated:3 out of 5 stars
 
Hi,

Thank you for your question.

The Unix tool you want to use is tr, short for translate.

tr takes two sets of characters and replaces the first set with the
second set on standard input and sends it to standard output.

For example if you have a file text.txt with
c:\tools\arizona\framework then you would write this:

tr '\\' '/' < text.txt

The output is then:

c:/tools/arizona/framework 

This says: look for all backslashes (the first backslash is to escape
the second one) and replace them with forward slashes on standard
input that you're reading from the file text.txt

For more information on tr you can have a look here:

Very short guide to sed, tr, cut and od
http://www.canberra.edu.au/~sam/whp/sed-tricks.html

However what you need to do is summed up in the command line above.

I hope this answers your question. If anything is unclear or you
require any clarifications please do not hesitate to ask.

Thanks.
endo

Search strategy

tr unix
://www.google.com/search?hl=fr&ie=UTF-8&oe=UTF-8&q=tr+unix&lr=

Request for Answer Clarification by cheekoo1-ga on 23 Dec 2003 16:12 PST
endo thanks for the answer, but I need something either in DOS's own
script.I cannot use Perl, or any of the UNIX utilities like tr or
SED,AWK as suggested by you, as I cannot assume their presence on a
particular system.

I have to use this in a makefile where I am getting errors like 
D:cvsarznarzn/buildfwrk/src/com/arzoon/util instead of
D:cvs/arzn/arzn/buildfwrk/src/com/arzoon/util. if you can tell me a
way of doing it either in a makefile on WINDOWS or a DOS batch/cmd
file, the answer is yours.

I am trying to do something like 
AZN := $(shell perl -e 's/\\/\//gc' $ARZN) , have not succeeded yet ?

Clarification of Answer by endo-ga on 24 Dec 2003 14:38 PST
Hi,

I'm very sorry about the confusion.

How about using one of these free utilities for DOS? There's a DOS
version of SED on the following page:

TEXT SEARCH and REPLACE
http://members.cox.net/dos/txtms01.htm#textsr

You could include this with your program.

I hope this helps. If it doesn't suit you, please let me know and I'll
do my best to find something that pleases you.

Thanks.
endo

Request for Answer Clarification by cheekoo1-ga on 27 Dec 2003 12:46 PST
Endo,
   Sorry for the belated reply.However, my current implmentation does
not allow me to use anything other than DOS.I already have a
pre-existing framework of shell scripts(DOS on W2k) and (bash on
*nix), so I have to stick to it.
   If there was a way of assigning a value from a PERL program into a
DOS variable, maybe that would work too.But I do not know of any.
Something like the DOS equivalent of
ARZN=`perl -e foobar.pl` on UNIX

Clarification of Answer by endo-ga on 27 Dec 2003 13:13 PST
Hi,

Can you write the value to a file, then read it back again in DOS?
e.g. you could write the Perl result to a ramdisk, or a temp file,
then read it back again.

Thanks.
endo

Request for Answer Clarification by cheekoo1-ga on 30 Dec 2003 10:05 PST
I can definitely do that ...using echo I believe.
But how could i read it back into a variable in
DOS ? I do not think that it has anything like 
"source" in UNIX.
cheekoo1-ga rated this answer:3 out of 5 stars
The ANSWER giver seems to be well informed, but almost all answers
that were given were nice ideas or suggestions, none really hit the
point like the way, TIM's comment did.Also I needed the answers very
strictly in the DOS realm however most of the answers given by ENDO
required an external tool/script on Windows.Finally there were no code
samples, something that I was really looking for, being NOT SO
EXPERTISH in DOS scripting.

Comments  
Subject: Re: DOS shell Question : Path conversion from DOS to UNIX pathnames.
From: tim7ad-ga on 30 Dec 2003 13:43 PST
 
cheekoo1,

Use DOS's FOR command to do what your asking. The following will work
for the example you gave.

  @echo off
  pushd ..\..
  set VARVAL=%CD%
  popd 
  FOR /f "tokens=1,2,3,4 delims=\" %%i in ('echo %VARVAL%') do SET
VARVAL2=%%i/%%j/%%k/%%l

  echo %varval% has been converted to %varval2%

  rem VARVAL2 is the new variable with the backslashes converted to
unix style forward slash


I'm not sure what version of DOS you are using. The example above
works with a batch file on Windows NT, 2000 and XP.

Hope this helps.
Tim
Subject: Re: DOS shell Question : Path conversion from DOS to UNIX pathnames.
From: cheekoo1-ga on 30 Dec 2003 14:12 PST
 
That was the answer that I was gravitating towards.
Thanks TIM ... and I am sorry, ENDO, I guess TIM 
gave the perfect answer that I was looking for.
Subject: Re: DOS shell Question : Path conversion from DOS to UNIX pathnames.
From: tim7ad-ga on 31 Dec 2003 08:24 PST
 
Thanks for the compliment cheekoo. Glad it was helpful.

-Tim

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy