Problem in sed because of multiple /(slash)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in sed because of multiple /(slash)
# 1  
Old 01-29-2009
Java 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 [the bolded string is a complete word have to replaced instead of singleslash].

Will this properly substitute the new word double/slash/ in the file.txt.

Please let me know how it will work.

Here i made the same script with back slash (\), to avoid the special meaning. Will it work.
sed "s/singleslash/double\/slash\//g" file.txt

Thanks.

Last edited by Arunprasad; 01-29-2009 at 10:57 AM..
# 2  
Old 01-29-2009
Try this:

Code:
sed 's!singleslash!double/slash/!g'

Regards
# 3  
Old 01-29-2009
the first character in the sed substitution string acts as the delimiter.
Therefore, you could do this:

sed -e "s@singleslash@double/slash/@g" file.txt
# 4  
Old 01-29-2009
Tools

It should work escaping the / with the \

you may also use another delimiter:

sed "s-singleslash-double/slash/-g" file.txt
# 5  
Old 01-29-2009
Thanks

Thanks for your quick replies,
with explanation...,

Could you please let me know how my suggestion will work,,
the one i updated at last of my post with back slash.

Thanks again.
# 6  
Old 01-29-2009
It will work

sed "s/singleslash/double\/slash\//g" file.txt

Personnaly I prefer using another delimiter for clarity
# 7  
Old 01-29-2009
I am feeling great

Thanks for your quick response.
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. Shell Programming and Scripting

Passing slash with sed: failure

Hi, I have a text file with the normal text like: rfio://castor/cern.ch/user/p/pooja/WorkArea/Fall11/QCD/QCD800To1000/bkg_40_2_yOo.root I want to make shell script which ask for the word to replace where it sud take "'/" variable as well. And change it to the pattern I need. Here in the... (3 Replies)
Discussion started by: nrjrasaxena
3 Replies

4. Shell Programming and Scripting

AWK or SED to replace forward slash

hi hope somebody can help, there seems to be bit on the net about this, but still cant make it work the way i need. i have a file live this mm dd ff /dev/name1 mm dd ff /dev/name2 mm dd ff /dev/name3 mm dd ff /dev/name4 i need to update /dev/name1 etc to /newdev/new/name1 etc so... (5 Replies)
Discussion started by: dshakey
5 Replies

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

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

7. Shell Programming and Scripting

How to replace comma by slash using sed in an UTF8 file

Hello all, I'd like to replace "," by "/" in a utf8 file from postion X to Y. Comma "," is also defined as delimiter. 12345678901234567890,123456789012345,12345678901234567890, aaaa,aaaa,aaaaa ,bbb,bbbb,bbbbb ,cccccc,cc , Result should be... (1 Reply)
Discussion started by: fmofmo
1 Replies

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

9. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: Abhidey
3 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