Substituting variable value in AWK /start/,/stop/


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substituting variable value in AWK /start/,/stop/
# 8  
Old 04-16-2009
Hi Ghostdog

And that pattern2 as well i want to call trough varaible thn how can i do this???
# 9  
Old 04-16-2009
look at how pattern1 is used. its the same.
# 10  
Old 04-16-2009
Hi ghostdog
Code:
a=pattern1
b=pattern2
awk -v var=$a,var1=$b '$0~var,$0~var1' file

Here what i used ......
can you correct me...... Its not working
# 11  
Old 04-16-2009
Code:
awk -v var=$a -v var1=$b '$0~var,$0~var1' file

next time, don't just say "it's not working". show how its not working by provided error messages if any, your input file samples etc.
# 12  
Old 04-16-2009
Hi ghostdog

Code:
-------here is my code which i have written (for bottleneck look at the code RED)------
#!/bin/ksh
for SID in `cat $HOME/appleora/dblist`
do
cd $HOME/appleora/$SID/admin/bdump
cat alert_${SID}.log >>$HOME/alert_${SID}.log
cd
if [ -f alert_${SID}.log ]
then
mv alert_${SID}.log alert_out.log
touch alert_${SID}.log
YESTERDAY=`TZ=aaa24 date +"%b %d"`
TODAY=`date +"%b %d"`
echo $TODAY
echo $YESTERDAY
#awk '/Apr 15/,/Apr 16/' $HOME/alert_out.log >> $HOME/alert_work.log
#awk '/$YESTERDAY/,/$TODAY/' $HOME/alert_out.log > $HOME/alert_work.log
awk -v var=$YESTERDAY,var1=$TODAY '$0~var,$0~var1' $HOME/alert_out.log > $HOME/alert_work.log
cat alert_work.log >> alert_${SID}.hist
grep ORA- alert_work.log >> alert.err
fi
for DBA in `cat $HOME/appleora/dbalist`
do
if [ `cat alert.err|wc -l` -gt 0 ]
then
mailx -s "${SID} ORACLE ALERT ERRORS" $DBA < alert.err
else
mailx -s "${SID} ORACHECK RUN SUCCESFULLY NO ERROR" $DBA
fi
done
rm -f alert.err
rm -f alert_work.log
done
 
Now 
-----Here is my $HOME/alert_out.log file on which i am doing search and i am intreested in content between Apr 15 and Apr 16----
Wed Apr 15 09:37:05 2009
Thread 1 advanced to log sequence 46
  Current log# 3 seq# 46 mem# 0: C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO03.LOG
Wed Apr 15 22:00:14 2009
Thread 1 advanced to log sequence 47
  Current log# 1 seq# 47 mem# 0: C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG
b_recovery_file_dest_size of 2048 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup
Errors in file c:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_5388.trc:
ORA-00600: internal error code, arguments: [LibraryCacheNotEmptyOnClose], [], [], [], [], [], [], []
Thu Apr 16 09:30:56 2009

that means o/p should be in green
=====================================
Now if i use 
#awk '/Apr 15/,/Apr 16/' $HOME/alert_out.log >> $HOME/alert_work.log
then i am getting desired output as well as i am getting mail thru mailx command 
=====================================
=====================================
if i use 
#awk '/$YESTERDAY/,/$TODAY/' $HOME/alert_out.log > $HOME/alert_work.log
then this file is get created > $HOME/alert_work.log this file bt with no content 
=====================================
=====================================
and if i use 
awk -v var=$YESTERDAY,var1=$TODAY '$0~var,$0~var1' $HOME/alert_out.log > $HOME/alert_work.log
as u suggested......
i am getting below message
sh oracheck.sh
Apr 16
Apr 15
awk: syntax error near line 1
awk: bailing out near line 1
=====================================

Now can u help me out......
# 13  
Old 04-16-2009
Code:
awk -v var="$YESTERDAY" -v var1="$TODAY" '$0~var,$0~var1' $HOME/alert_out.log > $HOME/alert_work.log

[*] running out of spoons....
# 14  
Old 04-16-2009
Hi vgersh99
I have tried with, as u have suggestd bt its giving me below error..........

Code:
Apr 16
Apr 15
oracheck.sh: Apr 15: not found
oracheck.sh: Apr 16: not found
awk: syntax error near line 1
awk: bailing out near line 1


Code:
awk -v var="$YESTERDAY" -v var1="$TODAY" '$0~var,$0~var1' $HOME/alert_out.log > $HOME/alert_work.log
awk -v var=`"$YESTERDAY"` -v var1=`"$TODAY"` '/$0~var/,/$0~var1/' $HOME/alert_out.log > $HOME/alert_work.log



I have tried out with both this optionss.....
but in both the cases its giving me same error
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

getting error while substituting variable using sed..

I am using script for substitute one variable with another variable like below... below code works fine... sed 's/'$sub_fun'/'$To_sub'/g' But when i run the same code from the script getting below errors.. sed: -e expression #1, char 7: unterminated `s' command please help....... (2 Replies)
Discussion started by: pamu
2 Replies

2. Shell Programming and Scripting

Trouble with sed and substituting a string with special characters in variable

Hey guys, I know that title is a mouthful - I'll try to better explain my struggles a little better... What I'm trying to do is: 1. Query a db and output to a file, a list of column data. 2. Then, for each line in this file, repeat these values but wrap them with: ITEM{ ... (3 Replies)
Discussion started by: ampsys
3 Replies

3. Shell Programming and Scripting

Substituting a shell variable in sed

Hi guys, I'm trying to figure out how to use a shell variable inside my sed command. I just want to remove a certain part of a path. I've tried three different combinations and none of them work. Here are the three combinations: echo $file | sed 's/'$test'//' echo $file | sed "s/$test//"... (7 Replies)
Discussion started by: chu816
7 Replies

4. UNIX for Dummies Questions & Answers

Variable is not substituting values

Hi All, OS HPUX 11.11 I am using following script to take controlfile backup. I have used SID variable to hold "ffin1" value, which I again subsitute in "'/db/ffin1/home/oraffin1/$SID_$wdate.ctl'" command. Well, after running this, SID variable does not subsittue it's value, while wdate... (6 Replies)
Discussion started by: alok.behria
6 Replies

5. UNIX for Dummies Questions & Answers

substituting variable value in AWK

Hi All, my requirement is as below. I need to replace a value in a particular column with a substitution variable(date value) and modified value of the current column value in the same position. for ex. i have a record like 02;aaaa;bbbbb;cccccc;dddddd;123456789;hhhhh;12hs;asdf ;... (3 Replies)
Discussion started by: ganesh_248
3 Replies

6. UNIX for Dummies Questions & Answers

Stop/Start vs. Restart

Is there any functional difference between: issuing separate stop/start commands like this; super (handler) (instance) stop super (handler) (instance) start versus issuing a single recycle command like this; super (handler) (instance) restart (3 Replies)
Discussion started by: Newbix
3 Replies

7. Shell Programming and Scripting

Servers Start and Stop

HI I am using below code to start and stop servers but it is not working ,how to run the script please suggest me ,if any errors in the script please let me know. #!/bin/bash IMS_START="/Webserver/AppServer/bin/startServer.sh" IMS_STOP="/Webserver/AppServer/bin/stopServer.sh" case "$1" in ... (1 Reply)
Discussion started by: RG18173
1 Replies

8. Shell Programming and Scripting

Substituting with value of variable in Sed

Hi, I have a program in which i have to substitute a TAG in a file with the value of a variable. Code Snippet: ---------------- myvar=1234 sed 's/_TAG_/$myvar/' infile outfile When I run this command, the _TAG_ in the "infile" is substituted with "$myvar" but NOT the value "1234"... (1 Reply)
Discussion started by: jyotipg
1 Replies

9. Shell Programming and Scripting

Substituting variable with current time

Hi all I have a script as follows :- #!/usr/bin/ksh IDT=`date +"%OH%M%S"` while true do echo ${IDT} sleep 1 done I need the time to show me the current runtime value for the time, however this returns the time as at the start of the script. Any ideas. Thanks JH (4 Replies)
Discussion started by: jhansrod
4 Replies

10. UNIX for Dummies Questions & Answers

Start/Stop Script

I'm a newbie to the Unix world Help! I have to maintain a host of Sybase database servers sitting on Unix Sun Solaris 8...I've been tasked with finding/creating a way to auto start/stop Unix via unix commands, specifically when the Unix servers need to be restarted we want Sybase to start... (2 Replies)
Discussion started by: jjv1
2 Replies
Login or Register to Ask a Question