Passing date into awk...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing date into awk...
# 1  
Old 06-02-2012
Passing date into awk...

Hi All....

I need to pass date into awk and parse logfile based on that.... i used both awk and /usr/xpg4/bin/awk... both are throwing up error.....


So here is the stuff...

when i use /usr/xpg4/bin/awk :
Code:
DATE=`date '+%Y %b %d'`
START=00
END=23
/usr/xpg4/bin/awk -v DATE={"$DATE"} -v START=$START -v END=$END '/DATE START/,/DATE END/' logfile.log  > processfile.txt

Error :

Code:
/usr/xpg4/bin/awk: inadmissible use of reserved keyword  Context is:
>>>     {2010 Jan 02}1023       <<<

when i use awk:

Code:
DATE=`date '+%Y %b %d'`
START=00
END=23
awk -v DATE={"$DATE"} -v START=$START -v END=$END '/DATE START/,/DATE END/' logfile.log  > processfile.txt


Error:
Code:
awk: syntax error near line 1
awk: bailing out near line 1


Can anyone think of y this error is happening??? How to finally pass date into awk???

Last edited by Scrutinizer; 06-02-2012 at 07:46 AM.. Reason: code tags
# 2  
Old 06-02-2012
Try something like:
Code:
awk -v dd="$DATE" -v s=$START -v t=$END '$0~dd FS s,$0~dd FS t' logfile.log

You cannot use END as a variable name, it is a reserved word....

Last edited by Scrutinizer; 06-02-2012 at 08:52 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 06-02-2012
Scrutinizer...

The Error was spot on!!! Cannot use END and variable name!!!

Code:
/usr/xpg4/bin/awk -v s="$START" -v e="$END" '/s/,/e/' logfile.log  > processfile.txt

Works perfectly fine!!!
# 4  
Old 06-03-2012
Doubt your posted code will work as you intended. I feel it will list everything from first record that contains the letter 's' to next record that contains letter 'e'

You should probably do:
Code:
/usr/xpg4/bin/awk -v s="$START" -v e="$END" '$0~s,$0~e' logfile.log  > processfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

2. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. UNIX for Dummies Questions & Answers

passing grepped date var into code

Hi Everyone, I am a bit new at learning this bash syntax. I have a problem at work that needs to be addressed. We find we are spending quite a bit of time killing old processes created by oracle replication that have been restarted later in the week. Because the replication takes time to... (3 Replies)
Discussion started by: bdby
3 Replies

4. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

5. UNIX and Linux Applications

Passing date parameter on Kshell command line

I need to execute a .ksh from command line. The ksh calls a control file and has 3 parameters. First parameter is a csv file, second the target table in oracle and third parameter is a date parameter. I am attempting the below from the ksh command line {code} => testfile.ksh filname.csv... (1 Reply)
Discussion started by: kobe24
1 Replies

6. Shell Programming and Scripting

Passing CURL a date argument (formatting)

Im trying to pass curl a list of arguments... one of which is a date... When I run from the command line it works fine but when i try to run the same from a script passing variables it reformats the date for some reason and doesn't work. Example: curlstring=xxxxxxxxxxx.xxx.xxx:8090/csv/... (1 Reply)
Discussion started by: atelford
1 Replies

7. Solaris

SFTP passing variables date

Hi, Anyone can help me on how to solve my problem not getting the actual $DATE saying . Here my scripts; #!/bin/sh DATE='20110331' sftp -oUserKnownHostsFile=/.ssh/known_hosts -oIdentityFile=/.ssh/id_rsa -b /source/transfer.sh server1@sftp.com <<EOF #tranfer.sh put... (3 Replies)
Discussion started by: fspalero
3 Replies

8. Shell Programming and Scripting

passing date parameter in cronjob

Hi All, I have a crontab entry for every 5 min running. 5 * * * * /tmp/scripts/ksh/CsVues_H.sh `date +%Y%m%d_%H` >> /tmp/scripts/ksh/Cronresult.log and I am passing the date parameter. ( `date +%Y%m%d_%H` ) But the parameter values which i am expecting inside the script is... (6 Replies)
Discussion started by: scorpio
6 Replies

9. Solaris

passing an input parameter like date thru jcl using BPXBATCH utility

Hi.... i need to pass the dates (from - to) as the input parameters thru jcl invoking BPXBATCH utility. I know that PARM will do the above functionality. But how the above dates passed through jcl will be linked in the java-db2 program to be used in sql queries in order to generate the report... (0 Replies)
Discussion started by: Sujatha Gowda
0 Replies

10. Shell Programming and Scripting

Passing Date as parameter with sh script

Hi I need to pass a date argument with my shell script. Can any one send me code for the same. eg For 15th Aug 2006. Iwant to pass parameter like this ./startenv.sh 08/15/2006. Everyday date argument must change. Will the below code work ? ./startenv.sh date '+%m/%d/%y' THanks... (1 Reply)
Discussion started by: pankajkrmishra
1 Replies
Login or Register to Ask a Question