LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-14-2009, 06:32 AM   #1
gibsosmart
LQ Newbie
 
Registered: Jul 2006
Location: Warangal, Andhra, INDIA
Posts: 4

Rep: Reputation: 0
change windows path to unix path


I have a path c:\windows\back\up
I need this string to be changed into /windows/back/up

I used the command
-bash-3.00$ echo \wind\back\up | sed 's/\\/\/g'
but the output is
windbackup

plz help me out

Thanks...
 
Old 09-14-2009, 06:35 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
You need another / right before the 'g'
 
Old 09-14-2009, 06:36 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by gibsosmart View Post
I have a path c:\windows\back\up
I need this string to be changed into /windows/back/up

I used the command
-bash-3.00$ echo \wind\back\up | sed 's/\\/\/g'
but the output is
windbackup

plz help me out

Thanks...
Check the output of the echo command without the sed command after it. I think you'll find it's not sending the output you anticipated to sed.
 
Old 09-14-2009, 06:39 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by gibsosmart View Post
I have a path c:\windows\back\up
I need this string to be changed into /windows/back/up

I used the command
-bash-3.00$ echo \wind\back\up | sed 's/\\/\/g'
but the output is
windbackup

plz help me out

Thanks...
Always use the simplest available method.

Code:
s="c:\windows\back\up"
s=${s/c:}
echo ${s//\\//}
result: /windows/back/up
 
Old 09-14-2009, 06:40 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Adding to pwc101's remark:

After fixing the echo command you need to escape the first \ in the sed statement too:

This should do what you want:
echo '\wind\back\up' | sed "s%\\\%/%g"

Hope this helps.
 
Old 09-14-2009, 07:05 AM   #6
gibsosmart
LQ Newbie
 
Registered: Jul 2006
Location: Warangal, Andhra, INDIA
Posts: 4

Original Poster
Rep: Reputation: 0
Talking

Used the following
expr "c:\wind\back\up" | awk '{ gsub(/\\/, "/"); print }'
 
Old 09-14-2009, 07:16 AM   #7
gibsosmart
LQ Newbie
 
Registered: Jul 2006
Location: Warangal, Andhra, INDIA
Posts: 4

Original Poster
Rep: Reputation: 0
Now I want to goto that directory in a shell script
like
my_cd.sh "c:\windows\back\up"
should change my directory to
/windows/back/up in my putty session.
 
Old 09-15-2009, 03:35 AM   #8
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by gibsosmart View Post
Now I want to goto that directory in a shell script
like
my_cd.sh "c:\windows\back\up"
should change my directory to
/windows/back/up in my putty session.
This version will change directories:

Code:
s="c:\windows\back\up"
s=${s/c:}
path=${s//\\//}
echo "Moving to $path"
cd $path
It's important that you realize the directory change won't normally persist after you exit the shell script. But there is a way to make this happen.

This example won't retain the directory change after the script exits:

Code:
$ ./script-name.sh
This example will:

Code:
$ . ./script-name.sh
See the extra dot?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unix Function call to get executable's path vharishankar Programming 13 04-20-2010 12:53 PM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
set up java_home path in /home/user/.bashrc but use path in /usr/lib/java vitalstrike82 Slackware 4 01-13-2009 11:25 PM
script to change unix path to windows path in all files csross Programming 8 04-29-2006 01:05 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 06:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration