sed variable issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed variable issue
# 1  
Old 11-27-2006
sed variable issue

I'm writting a krn shell script and i'm having an issue with a variable using sed.
If someone enters a variable with a " /" the sed command doesn't read it right.
example.
a='12000/10-DC'
b='12000/10-AC'

cat file | sed "s/$a/$b/"

How can i correct this issue? Will the fix to this problem also work if someone enters a variable without a " /" ? What is it called when a variable has a character like this? I didn't know how to search for this issue correctly.
Thanks.
Smilie
# 2  
Old 11-27-2006
Here is one workaround -- use delimiting characters that are not in the user-defined strings (assumes the # character is not in the strings):
Code:
a='12000/10-DC'
b='12000/10-AC'

cat file | sed "s#$a#$b#"

# 3  
Old 11-27-2006
Thanks it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

2. Shell Programming and Scripting

Issue in using variable within sed command

Hi All, I am trying to use a variable within the sed command but I am not able to get the output. When I am using the following command (without variable) its working fine: sed -n '/2011\/12\/10 18:11:11./,$p' < Log.txt > Delta_Log.txt But when I am putting the value 2011\/12\/10... (4 Replies)
Discussion started by: acoomer
4 Replies

3. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

4. Shell Programming and Scripting

variable issue

Hi, I'm sure that it's a very simple issue. this is a part of my code : while read ligne do result=`ls -R ../FILES/|grep "."$ligne"$"` echo $result done<TYPE_EXT_FILES.txt the echo return nothing (as my variable is empty). I'm sure that the problem... (10 Replies)
Discussion started by: skubann
10 Replies

5. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

6. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

7. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

8. Programming

Have issue with variable

Hi All, i am new to unix.. i have an issue with my unix script...let me explain the task that i want to make script.... i prepared script which will connect data base from my linux box using sqlplus cmd... however in that i want to use the variable like below.. select * from... (0 Replies)
Discussion started by: Shahul
0 Replies

9. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

10. Solaris

Variable Substitution Issue

#!/bin/ksh VAR_ONE=HELLO TEMP=ONE echo $VAR_${TEMP} ## Output is: ONE Hi, I want the output to echo HELLO and not ONE as the above script does. I know I am missing something with dollar substitution. Can anyone help me out ? Thanks. Cal (4 Replies)
Discussion started by: calredd
4 Replies
Login or Register to Ask a Question