sed command replaces \\ to \


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command replaces \\ to \
# 1  
Old 02-23-2009
sed command replaces \\ to \

I am using the following sed command to

##URL## with C:\\DOCUME~1\\abcde\\APPLIC~1\\URL

as
sed "s^$2^$3^g"

where $2 is ##URL##
and $3 is C:\\DOCUME~1\\abcde\\APPLIC~1\\URL

but i get the output as
C:\DOCUME~1\abcde\APPLIC~1\URL

How can i get the out put as "C:\\DOCUME~1\\abcde\\APPLIC~1\\URL"
# 2  
Old 02-23-2009
Your unnecessarily complex method is hiding what sed is doing. It appears you're not escaping enough.
Code:
sed 's/\//\/\/'

Initial '/' would output '//'
# 3  
Old 02-24-2009
i didnt really get this

my script is like this

#!/bin/bash
if [ $# -lt 3 ] ; then
echo -e "Wrong number of parameters."
echo -e "Usage:"
echo -e " FindReplace 'filepat' findstring replacestring\n"
exit 1
fi
echo $1 $2 $3
for i in `find . -name "$1" -exec grep -l "$2" {} \;`
do
#echo "iiiiiiiiiiiiiiiiiiiiiiiiiii"$i
mv "$i" "$i.sedsave"
sed "s^$2^$3^g" "$i.sedsave" > "$i"
echo "Replacing $2 with $3 in $i"
rm "$i.sedsave"
done

how will i put escaping into it so that \\ is not removed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output of sed command to another sed command

Hi All, I'm relatively new to Unix scripting and am trying to get my head around piping. I'm trying to take a header record from one file and prepend it to another file. I've done this by creating several temp files but i'm wondering if there is a cleaner way to do this. I'm thinking... (10 Replies)
Discussion started by: BigCroyd
10 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

How to replaces a value in a file after a particular string using perl?

I need to replace the value of notifications_enabled to 0 if the value already set to 1 and vice versa(not the other values and spaces remain same after the value changed). I tried the below program for that. Can any one help me out. file:test.cfg define host { hostgroups ... (2 Replies)
Discussion started by: praveen265
2 Replies

4. Red Hat

Dual NICs - When I 'ifup eth1' it replaces eth0

I've got an issue with a VMWare server running RHEL 6.3 that has dual E1000 NICs. I have configured the cards as I would normally do in /etc/sysconfig/network-scripts as ifcfg-eth0 and ifcfg-eth1. I can execute ifup eth0 and bring the interface up quite happily, however when I execute ifup eth1 it... (2 Replies)
Discussion started by: phaedrus
2 Replies

5. Shell Programming and Scripting

Search and replaces lines with a variable number

Helo, I have a kml file with 39.000 lines. Need search text and add a sequential number before text. Original file <Placemark> <name>POI</name> <styleUrl>#waypoint</styleUrl> <Point> <coordinates>2.104510,41.341900</coordinates> </Point> ... (3 Replies)
Discussion started by: saba01
3 Replies

6. HP-UX

Which command replaces "ntsysv" of Linux in HP-UX?

Which command replaces "ntsysv" of Linux in HP-UX? Which command can I use in HP-UX to see all running processes ? :( (3 Replies)
Discussion started by: manalisharmabe
3 Replies

7. Shell Programming and Scripting

How would I do 2 search & replaces in 1 Perl statement?

Hi All, The below code successfully tails the logfile.log file and colors every word "ERROR" in RED, thanks to the Perl statement below. However, would anyone know how to append 1 additional search/replace to the Perl statement below, to color the word "SUCCESS" in GREEN (using ANSI \e ... (3 Replies)
Discussion started by: chatguy
3 Replies

8. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

9. Shell Programming and Scripting

sed replaces all matched strings!!!

hi sed -e '/<group>/!s/group\(.*\)/group\: files compat/' /etc/nsswitch.conf returns group: files compat netgroup: files compat How to prevent changing netgroup entry?? thank you (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

10. News, Links, Events and Announcements

New Tool Searches and Replaces SCO Code

See this article: http://story.news.yahoo.com/news?tmpl=story&cid=74&ncid=738&e=9&u=/cmp/20030809/tc_cmp/13000487 (3 Replies)
Discussion started by: Neo
3 Replies
Login or Register to Ask a Question