How to parse slash / in sed command..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to parse slash / in sed command..
# 1  
Old 10-31-2008
How to parse slash / in sed command..

Hi All,

I am trying to replace paths with \ (as in NT) with / (as in Unix) in a script using sed. Following is the command I use:

sed "s/e:\Kenny_test\csv_files/var/opt/ciw/data/outbound/g" EMEA4710.SQL > test

the string to replace is e:\Kenny_test\csv_files
the target string needs to be /var/opt/ciw/data/outbound

Could you please help(do I need to use any "escape \".. I get a parsing error even after that..

Many Thanks & Regards,
Abhijit
# 2  
Old 10-31-2008
you have to protect all / and \ characters
/ -> \/
\ -> \\

s/e:\\win\\dir/\/var\/opt\/bullshit\//g
# 3  
Old 10-31-2008
or use a different delimiter for the substitution command.
the first character after the s will be taken as the delimiter so
Code:
sed "s_\\unc\path_/unix/style/path_"

should do the trick, and still remain fairly readable
# 4  
Old 10-31-2008
sorry, stupid me.
you stilll have to quote the backslash
Code:
echo '\\unc\path' | sed  's_\\\\unc\\path_/unix/path_'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed not working properly with slash /

my testfile is aspsun1:usasp000$cat testfile open connection put $TMPDIR/SUNIA.PJ080202.ENGRPTBZ.<OPERATOR>.133 <FILENAME> quit my problem statement is to replace the line with put command with 2 different lines a cd command and then put line. from put... (2 Replies)
Discussion started by: gotamp
2 Replies

2. Shell Programming and Scripting

sed command to replace slash in date format only

Hello experts. I haven't been able to find a solution for this using the sed command. I only want to replace the forward slash with string "FW_SLASH" only if there's a number right after the slash while preserving the original number. I have a file containing 2 entries: Original File:... (5 Replies)
Discussion started by: pchang
5 Replies

3. UNIX for Dummies Questions & Answers

Replace Forward Slash with sed

i need to replace '/' forward slash with \/(backward slash follwed by a forward slash) using sed command when the forward slash occurs as a first character in a file.. Tried something like this but doesn't seem to work. find $1 -print0 | xargs -0 sed -i -e 's/^\//\\\//g' Can someone... (19 Replies)
Discussion started by: depakjan
19 Replies

4. Shell Programming and Scripting

sed to insert a slash and keep text

I have: /path/to/my/fixdir/MD1234567.tar I want to have: /path/to/my/fixdir/MD/1234567.tar fixdir never changes but MD does and how many numerical digits does. I want something like: /usr/bin/sed 's/fixdir\/../fixdir\/..\//' This ends up: /path/to/my/fixdir/../1234567.tar But... (3 Replies)
Discussion started by: crowman
3 Replies

5. Shell Programming and Scripting

sed command to parse Apache config file

Hi there, am trying to parse an Apache 'server' config file. A snippet of the config file is shown below: ..... ProxyPassReverse /foo http://foo.example.com/bar ..... ..... RewriteRule ^/(.*) http://www.example.com/$1 RewriteRule /redirect https://www.example1.com/$1 ........ (7 Replies)
Discussion started by: jy2k7ca
7 Replies

6. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

7. Shell Programming and Scripting

Problem in sed because of multiple /(slash)

Hi All, My target is to replace the text in a file.txt to newword, say "singleslash" to "double/slash/" NOTE: The replacing word itself contains the symbol /(slash). here is my code sed "s/singleslash/double/slash//g" file.txt . Will this properly substitute the new word... (6 Replies)
Discussion started by: Arunprasad
6 Replies

8. Shell Programming and Scripting

awk/sed Command: To Parse Stament between 2 numbers

Hi, I need an awk command that would parse the below expression Input Format 1 'Stmt1 ............................'2 'Stmt2 ............................'3 'Stmt3 ............................'4 'Stmt4 ............................'5 'Stmt5 ............................'6 'Stmt6... (1 Reply)
Discussion started by: rajan_san
1 Replies

9. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

10. Shell Programming and Scripting

Help with SED and forward slash

Using the script: (Called replaceit) #!/bin/ksh String=$1 Replace=$2 sed -e "s/${orig}/${new}/g" oldfile.txt > newfile.txt In oldfile.txt, I'm looking for: getenv("Work") And change it To: /u/web I execute the script: replaceit "getenv(\""Work\"")" /u/web I'm getting sed... (3 Replies)
Discussion started by: gseyforth
3 Replies
Login or Register to Ask a Question