Sponsored Content
Top Forums Shell Programming and Scripting Variable not passed to the sed command Post 302937572 by emily on Friday 6th of March 2015 09:20:29 AM
Old 03-06-2015
Quote:
Originally Posted by RavinderSingh13
Hello emliy,

Not tested though but could you please try following command and let me know if this helps.

Code:
sed -i 's/L1ITMBLT.root/L1ITMBLT_$Index.root/g' $CONFIGFILE

Thanks,
R. Singh
Did not work...Smilie

---------- Post updated at 09:20 AM ---------- Previous update was at 09:16 AM ----------

Quote:
Originally Posted by Scrutinizer
The variable Index needs to be set outside the here-document, if you want to use it inside the here-document.
I modified the script as following, did not help either
Code:
#!/bin/sh                                                                                                                    
CONFIGFILE=run_DttfFromCombinedPrimitives_cfg.py
Index=trash

for FILE in *txt
do
    echo $FILE
    ScriptName=$(echo $FILE | awk '{split($FILE, a, ".txt"); print a[1]}')
    cat > $ScriptName.sh <<EOF                                                                                               
#!/bin/sh                                                                                                                    
sed -i "s/InputFile[a-zA-Z0-9]*/${FILE}/g" $CONFIGFILE                                                                       
Index=$(echo $FILE | awk '{match($0,/\_.*\_/);print substr($0,RSTART,RLENGTH+1)}')                                           
sed -i 's/L1ITMBLT.root/L1ITMBLT_$Index.root/g' $CONFIGFILE                                                                  
#cmsRun $CONFIGFILE                                                                                                          
EOF                                                                                                                                                                                                                               

done

the output is following
Code:
#!/bin/sh                                                                                                                    
sed -i "s/InputFile[a-zA-Z0-9]*/InputFile_009_0.txt/g" run_DttfFromCombinedPrimitives_cfg.py
Index=_009_0
sed -i 's/L1ITMBLT.root/L1ITMBLT_trash.root/g' run_DttfFromCombinedPrimitives_cfg.py
#cmsRun run_DttfFromCombinedPrimitives_cfg.py

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

variable passed to awk

Anybody know what's wrong with this syntax? awk -v job="$job" 'BEGIN { FS="|"} {print $1,$2," ",$4," ",$3\n,$5,"\n"}' list It's keeping give me this message: awk: syntax error near line 1 awk: bailing out near line 1 It seems awk has problem with my BEGIN command. Any... (8 Replies)
Discussion started by: whatisthis
8 Replies

2. UNIX for Dummies Questions & Answers

variable passed to awk

Does anybody know how to print a variable passed to awk command? awk -F"|" 'BEGIN {print $job,"\n","Question \n"} {print $1,$2$4," ",$3}' "job=$job1" file1 I am trying to pass job the variable job1. the output is blank. ?? (3 Replies)
Discussion started by: whatisthis
3 Replies

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

4. Shell Programming and Scripting

My variable cannot be passed through into my path

Hi, Can you please help. I am scripting in sh and I am trying to simply copy one directory to another but for some reason my variables are not recognised? echo "The latest version of the program is being found......." cd $SOFTWARE/src/$progname version=`ls $SOFTWARE/src/$progname | grep... (13 Replies)
Discussion started by: cyberfrog
13 Replies

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

6. Shell Programming and Scripting

Why Perl Subroutine Passed In Variable is 1?

The following subroutine prints 1 instead of the content of the Equipment variable. Can someone tell me why? #!c:/perl/bin/perl.exe # use strict 'vars'; my $Equipments = "data/equips.txt"; unless (open(EQUIP_FH, "$Equipments")) { print "errors: $Equipments\n"; # This line prints... (1 Reply)
Discussion started by: tqlam
1 Replies

7. UNIX for Advanced & Expert Users

Value of variable not getting passed in child script

Hi, I am facing a challenge in fixing an issue in my installation scripts.Here is a situation: There are 3 files which are invoked at a below given order: Installer.ksh----->Installer.xml(Ant script)------->common.ksh I am outputting a message from common.ksh at a terminal, after that trying to... (3 Replies)
Discussion started by: baig_1988
3 Replies

8. Shell Programming and Scripting

In the sh file variable is not being passed on.

I am having difficulties with the fllowing script: !/bin/sh voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/ echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log for audiofile in `ls $voicemaildir/*.wav`; do transcriptfile=${audiofile/wav/transcript} ... (4 Replies)
Discussion started by: ghurty
4 Replies

9. Shell Programming and Scripting

Variable passed as argument

I have a script. #!/bin/sh cur_$1_modify_time=Hello echo "cur_$1_modify_time" When I run like sh /root/script1 jj I expect value "Hello" being assigned to variable "cur_jj_modify_time" and output being "Hello" ie echoing $cur_jj_modify_time But the output comes as # sh... (3 Replies)
Discussion started by: anil510
3 Replies

10. Shell Programming and Scripting

Bash variable not being passed

In the bash below the variable date displays in the echo. However when I use it in the for loop it does not. Basically, the user inputs a date then that date is converted to the desired format of (month-day-year, no leading 0). That input is used in the for loop to return every file that matches... (5 Replies)
Discussion started by: cmccabe
5 Replies
All times are GMT -4. The time now is 12:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy