Sponsored Content
Top Forums Shell Programming and Scripting I can't seem to pass variables properly into a nawk statement Post 302180151 by era on Sunday 30th of March 2008 05:52:55 AM
Old 03-30-2008
In awk, $m means the field number indicated by the number in the variable m. So no wonder that part didn't work.

Something tells me the values of your variables are not completely right. We saw that m equals "Mar" but what about n? I would say that what you have ought to work but I haven't looked that closely.

As an aside, date has options to output just the month name or the day within the month; see its manual page for details. That's also more portable because the default date output format depends on the user's locale, etc.

You are not using e for anything. I would advise against using backticks -- just redirect the output straight where you want it. But the nawk script looks like a promising start.

P.S. The log file is probably growing while you work so could it be that you got unlucky, and the last line didn't happen to have today's date when you tested that awk script?

Last edited by era; 03-30-2008 at 06:55 AM.. Reason: Add P.S.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies

2. Shell Programming and Scripting

is it possible to pass external variable values to nawk?

Dear friends, please tell me how to pass the external variable values to the nawk command. length=`expr $len2 - $len1` i need to pass $length to following nawk command as mentioned below. nawk '{if((x=index($0,"W/X"))>0){id=substr($0,x, $length);print x;print id;}}' filename1 but I am... (1 Reply)
Discussion started by: swamymns
1 Replies

3. Shell Programming and Scripting

Shell script not processing if statement properly

Hi I am trying to create a shell script that will look for a contracthead file first and if the contract head file does not exist on day1 exit script. Now on day2 if contracthead exists or not run the script uploading files in order such as contract line then contract contact so the... (2 Replies)
Discussion started by: jonathan184
2 Replies

4. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

5. AIX

can't parse this nawk statement

hi all i have the following portion in an xml file: </n:AOMessage> <?xml version="1.0" encoding="UTF-8"?> <n:AOMessage xmlns:n="urn:ao:hs:update:shell" xmlns:bo="urn:ao:hs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ao:hs:update:shell... (0 Replies)
Discussion started by: chipahoys
0 Replies

6. Shell Programming and Scripting

Can't get shell parameters to pass properly to sqlplus

Gurus, The issue I'm having is that my Shell won't accept SQL parameters properly...... Here's they way I'm running it.... applmgr@ga006hds => sh CW_MigrationDeployScript.sh apps <appspwd> <SID> '01-JAN' '31-MAR' The process just hangs not submitting the SQL job... ... (3 Replies)
Discussion started by: WhoDatWhoDer
3 Replies

7. Shell Programming and Scripting

Pass parameter to nawk from shell script

I need to parse log files using nawk, but I'm not able to pass script input argument (date) to nawk, for example: ------------ #!/bin/ksh read date nawk -F, '{if($1==date) print $4" "$5}' ------------- Is there a way to pass an argument to nawk from shell script. Many thanks... (8 Replies)
Discussion started by: samer.odeh
8 Replies

8. Shell Programming and Scripting

Bash-how to properly READ and PASTE variables.

Recently i made a script for a project at molecular dynamics but am stuck at the last step.The thing i want to do is to ask the user to input the number of particles, then replace the bolded numbers at lines 9 and 17.. code #!/bin/bash #read number of particles echo "insert the number of... (2 Replies)
Discussion started by: arisinhell
2 Replies

9. Shell Programming and Scripting

How to pass nawk variable to shell within the same script?

Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it... (4 Replies)
Discussion started by: Optimus81
4 Replies

10. Shell Programming and Scripting

Need to pass shell arguments into Nawk/awk

Hi, I am in critical need of help, Thanks a ton for your help. I need to know how to pass the shell argument into nawk code in AIX. so that my file gets passed into that awk script and it can execute it part. To be detail, i have more than 100 files and in those files a particular field... (6 Replies)
Discussion started by: Selva_2507
6 Replies
DATE(1) 							   User Commands							   DATE(1)

NAME
date - print or set the system date and time SYNOPSIS
date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] DESCRIPTION
Display the current time in the given FORMAT, or set the system date. -d, --date=STRING display time described by STRING, not `now' -f, --file=DATEFILE like --date once for each line of DATEFILE -ITIMESPEC, --iso-8601[=TIMESPEC] output date/time in ISO 8601 format. TIMESPEC=`date' for date only, `hours', `minutes', or `seconds' for date and time to the indi- cated precision. --iso-8601 without TIMESPEC defaults to `date'. -r, --reference=FILE display the last modification time of FILE -R, --rfc-822 output RFC-822 compliant date string -s, --set=STRING set time described by STRING -u, --utc, --universal print or set Coordinated Universal Time --help display this help and exit --version output version information and exit FORMAT controls the output. The only valid option for the second form specifies Coordinated Universal Time. Interpreted sequences are: %% a literal % %a locale's abbreviated weekday name (Sun..Sat) %A locale's full weekday name, variable length (Sunday..Saturday) %b locale's abbreviated month name (Jan..Dec) %B locale's full month name, variable length (January..December) %c locale's date and time (Sat Nov 04 12:02:33 EST 1989) %C century (year divided by 100 and truncated to an integer) [00-99] %d day of month (01..31) %D date (mm/dd/yy) %e day of month, blank padded ( 1..31) %F same as %Y-%m-%d %g the 2-digit year corresponding to the %V week number %G the 4-digit year corresponding to the %V week number %h same as %b %H hour (00..23) %I hour (01..12) %j day of year (001..366) %k hour ( 0..23) %l hour ( 1..12) %m month (01..12) %M minute (00..59) %n a newline %N nanoseconds (000000000..999999999) %p locale's upper case AM or PM indicator (blank in many locales) %P locale's lower case am or pm indicator (blank in many locales) %r time, 12-hour (hh:mm:ss [AP]M) %R time, 24-hour (hh:mm) %s seconds since `00:00:00 1970-01-01 UTC' (a GNU extension) %S second (00..60); the 60 is necessary to accommodate a leap second %t a horizontal tab %T time, 24-hour (hh:mm:ss) %u day of week (1..7); 1 represents Monday %U week number of year with Sunday as first day of week (00..53) %V week number of year with Monday as first day of week (01..53) %w day of week (0..6); 0 represents Sunday %W week number of year with Monday as first day of week (00..53) %x locale's date representation (mm/dd/yy) %X locale's time representation (%H:%M:%S) %y last two digits of year (00..99) %Y year (1970...) %z RFC-822 style numeric timezone (-0500) (a nonstandard extension) %Z time zone (e.g., EDT), or nothing if no time zone is determinable By default, date pads numeric fields with zeroes. GNU date recognizes the following modifiers between `%' and a numeric directive. `-' (hyphen) do not pad the field `_' (underscore) pad the field with spaces ENVIRONMENT
TZ Specifies the timezone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used. AUTHOR
Written by David MacKenzie. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for date is maintained as a Texinfo manual. If the info and date programs are properly installed at your site, the command info date should give you access to the complete manual. date (coreutils) 4.5.3 October 2002 DATE(1)
All times are GMT -4. The time now is 08:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy