How to use sed when a match has forward slashes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use sed when a match has forward slashes
# 1  
Old 08-06-2012
How to use sed when a match has forward slashes

I'm trying to replace an alias with its match using sed but the match contains forward slashs so it causes the sed command to throw a garbled message..


cmd_list.txt sample
Quote:
PDCONFIG
AIX_myserver_1011_vintella.sudoers_cmndalias sample
Quote:
PDCONFIG=/usr/bin/pdconfig
I'm trying to use the below but like I say it throws a garbled message. Not sure what the way around this is

Code:
while read cmd_list
do
cmd_replace=$(grep -w $cmd_list AIX_myserver_1011_vintella.sudoers_cmndalias)
sed "s/${cmd_list}/${cmd_replace}/g" AIX_myserver_1011_vintella.sudoers_entries_2_A > new_out.txt
mv new_out.txt AIX_myserver_1011_vintella.sudoers_entries_2_A
done < cmd_list.txt

# 2  
Old 08-06-2012
Code:
sed "s:${cmd_list}:${cmd_replace}:g"

# 3  
Old 08-06-2012
try with

Code:
 
sed "s,${cmd_list},${cmd_replace},g"

# 4  
Old 08-06-2012
Try another separator:
Code:
sed "s!${cmd_list}!${cmd_replace}!g" AIX_myserver_1011_vintella.sudoers_entries_2_A > new_out.txt

# 5  
Old 08-06-2012
In short you can use any symbol as seperator other than / Smilie
# 6  
Old 08-06-2012
Quote:
Originally Posted by sam05121988
In short you can use any symbol as seperator other than / Smilie
Except for a newline or a backslash.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed how to remove "forward shash"

I am trying to remove "forward shash" using sed it was not working 666,server1, 00973 N/A RDF1+TDEV RW 1035788 i need to remove " N/A" and "RW" I need output 666,server, 00973 , RDF1+TDEV , 1035788 (4 Replies)
Discussion started by: ranjancom2000
4 Replies

2. UNIX for Advanced & Expert Users

Traverse backwards based on forward pattern match

Hi, I have a file containing records of this format. I need to show output of all header of the sets containing recn:rvn records. The sets appear in my file like below. #set 1 header1:hv1 rec1:rv1 rec2:rv2 rec3:rv3 ....... ...... recn:rn #set 2 header1:hv1 rec1:rv1 rec2:rv2... (3 Replies)
Discussion started by: adurga
3 Replies

3. Shell Programming and Scripting

Using SED to copy/paste with slashes and tabs.

I have: 2012/01_January/Kite/foldername/otherfoldername/placeholderBlue I want to end up with: /foldername/otherfoldername/2012/01_January/Kite/Blue Basically take everything before the first tab and put it in the place of the consistently named word placeholder and add a slash in place... (2 Replies)
Discussion started by: crowman
2 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. Ubuntu

Iptables forward traffic to forward chain!!!

Hi, I am new to linux stuff. I want to use linux iptables to configure rule so that all my incoming traffic with protocol "tcp" is forwarded to the "FORWARD CHAIN". The traffic i am dealing with has destination addresss of my machine but i want to block it from coming to input chain and somehow... (0 Replies)
Discussion started by: arsipk
0 Replies

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

7. Shell Programming and Scripting

sed - how to remove trailing slashes

I know you can remove trialing slashes using: #echo "/tmp/one/two/three////" | sed "s,/$,," /tmp/one/two/three/// But I want to know how to make it remove all trialing flashes in the front, and in the start, so the end result is: tmp/one/two/three Anyone have any idea how to do this... (6 Replies)
Discussion started by: EXT3FSCK
6 Replies

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

9. UNIX for Dummies Questions & Answers

sed command for using with back slashes

hi all, im trying to use a sed command to remove all occurenes of \p\g what i used so far is : sed 's!\p\g!!g' file but this doesnt work ? Any ideas, thanks for helping. (2 Replies)
Discussion started by: seaten
2 Replies

10. UNIX for Dummies Questions & Answers

UNIX and forward slashes

Hey, This is probably going to sound like an immensely stupid and dull question, but can someone please tell me whether the forward slash on the web address (http://) signifies that it is running on UNIX? hanks (1 Reply)
Discussion started by: steverocliffe
1 Replies
Login or Register to Ask a Question