using the sed command with variable subsitution???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using the sed command with variable subsitution???
# 1  
Old 09-18-2003
Tools using the sed command with variable subsitution???

how much do you know on using the sed commands within a diff command? I'm currently using one long command when robot runs that... when the diff command is ran that the < and > signs at the beginning of each line are changed to the environment name that they came from... making it easier to review...

diff $e1file $e2file | sed -e 's/^</$e1nm /1' -e 's/^>/$e2nm /1' > $dfnm

the variables above are... e1file is first file; e2file is the second environment code file; ^< will give me the < sign that is in the first position on a line; e1nm is subsitution value for first file;
e2nm is subsitution value for first file; dfnm is the name of the resulting diff file

The problem I'm having with this is that the subsitution part wants to change the < sign to "$e1nm" and not to say "file1" ... do anyone know how I can get a variable subsitution to work in this diff/sed command?
# 2  
Old 09-18-2003
Lightbulb

found it...

I was using the single quote (') instead of the double quote (")....

diff $e1file $e2file | sed -e "s/^</$e1nm /1" -e "s/^>/$e2nm /1" > $dfnm


Thanks!
Harold
# 3  
Old 09-18-2003
Thanks for posting your solution... I wish more folks would follow your example... Or reply at least saying that their problem was resolved or unresolved.



Many do but many more do not...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using a variable in sed command

Hi All, Please help me with the below problem if then $a=" " fi echo "ABC1abc" | sed 's/a/'$a'/' The required output is : ABC abc But I am getting the below error: sed: -e expression #1, char 4: unterminated `s' command Please help. (6 Replies)
Discussion started by: rahulsk
6 Replies

2. UNIX for Beginners Questions & Answers

Variable in sed command

Hi All, How can i use a variable in a sed command ? I cant seem to get it to work as at present its just printing $i at the start of every line rather than the variable $1. sed -e "s/^/\$i,|/" Any help would be appreciated. (3 Replies)
Discussion started by: mutley2202
3 Replies

3. Shell Programming and Scripting

Using a variable in sed command

Hi All, Can I use a variable (using this variable as a counter) in sed cmd? something like below sed -n '${COUNT}p' But it's not working. Pls help. Thanks. Regards, Amee export COUNT=1 export COUNTER=`cat ${BINPATH}/$ALLOC_FILE.clean_1 | wc -l | tr -d " "` while ... (3 Replies)
Discussion started by: Amee5
3 Replies

4. Shell Programming and Scripting

sed command with variable

Hi, I want to insert some text in the begning of each line. But issue is the text that i want to insert is stored into one variable. so my command look like constr="`date | awk '{print $3"-"$2"-"$6}'`",MXGBTST1" " sed 's/^/\$constr/g' alert_temp.csv but sed command instead of taking... (3 Replies)
Discussion started by: ranvijaidba
3 Replies

5. Shell Programming and Scripting

sed command to take variable

I have file File1.txt in which i have to replace a text using sed command File1.txt contents EURAMOUNTTOBEREPLACED I have a AIX shell script for replacing the text AMOUNTTOBEREPLACED Contents of the shell script sum=27 sed 's/AMOUNTTOBEREPLACED/"$sum"/g' File1.txt >> temp mv temp... (5 Replies)
Discussion started by: bk_12345
5 Replies

6. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

7. Shell Programming and Scripting

Passing a variable to sed command

Hi guys, I wanted to pass a variable to the sed command which tells which line to be deleted. a=2; echo $a; sed '$ad' c.out it is throwing an error. sed: 0602-403 "$a"d is not a recognized function. I even tried "$a" and \$a.. but it is of no use. Can you please correct me... (6 Replies)
Discussion started by: mac4rfree
6 Replies

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

9. Shell Programming and Scripting

Sed subsitution on loop output in shell script

I have a forloop which checks a log for a set of 6 static IP addresses and each IP found is logged to a file which is then mailed to me. After the forloop I always have a text file that may contain up to 6 IP addresses or may contain 0. What I want to do is substitute the IP addresses (if any)... (2 Replies)
Discussion started by: Moxy
2 Replies

10. Shell Programming and Scripting

Need a sed command that uses variable

Hi , Seen some of wonderful posts. Please have look at my problem. I have a text file ketkee.txt , which look like below. GATES := apple mango banana XMLCHECK := red blue green pink My requiement is to find the line that has XMLCHECK in it. and append two variables followed by a space... (2 Replies)
Discussion started by: ketkeep
2 Replies
Login or Register to Ask a Question