Sponsored Content
Full Discussion: Using variable inside awk
Top Forums Shell Programming and Scripting Using variable inside awk Post 302341604 by rdhanek on Thursday 6th of August 2009 09:10:23 AM
Old 08-06-2009
My basic requirement is to grep for the previous hour data. and my timestamp format is something like thisshown below.
Code:
(08/06/2009 05:48:45.992)(:)  
(08/06/2009 05:48:46.641)(:)

as there is a zero before the Hr, i can't just use
Code:
`date '+ %m/%d/%Y H'`

Instead i am using a bash file as shown below. I am able to get the date format but while using awk i am getting error. Please help me if there is any alternative for this requirement or any change needed in awk format? I am using sunOS box.
Code:
#!/bin/bash
genexpression()
{
stime=`date '+ %H'`
stime=`expr $stime \- 1`
if (( $stime < 10 ))
then
stime=0${stime}
fi
export express=`date '+%m/%d/%Y'`\ $stime
}
genexpression
echo $express
awk "/$express/{print}" test.log

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

variable inside awk '{print $c}'

i'm trying to do this (in bash darwin); echo "give me some words: " read a c=2 # this is get by other ways echo $a | awk '{print $c}' # i want to print the column given # by de $c variable if there is someone understand what i pretend... (3 Replies)
Discussion started by: Tártaro
3 Replies

2. Shell Programming and Scripting

getting variable inside awk

Hi All, I have awk script for replacing the nth ocurance of a string in an xml file... My code is like this FILETYPE=xml TAGNAME=type OCCURANCE=$1 TAGVALUE=valueur echo OCCURANCE:$OCCURANCE echo TAGNAME:$TAGNAME echo TAGVALUE:$TAGVALUE awk -v n=$OCCURANCE -v... (1 Reply)
Discussion started by: subin_bala
1 Replies

3. Shell Programming and Scripting

How to use same variable value inside as well as outside of the awk command?

Hi Jim, The following script is in working state. But i m having one more problem with awk cmd. Could you tell me how to use any variable inside awk or how to take any variable value outside awk. My problem is i want to maintain one property file in which i am declaring variable value into that... (12 Replies)
Discussion started by: Ganesh Khandare
12 Replies

4. Shell Programming and Scripting

Variable inside AWK printf

Hi, Is it possible to print a variable inside awk printf ?? the above is not working (13 Replies)
Discussion started by: selvankj
13 Replies

5. Shell Programming and Scripting

Using variable inside awk

Hi, Please help me how to use variables inside awk in code below: ll | awk -v "yr=`date '+%Y'`" -v "mnth=`date '+%m'`" -v Jan=1 -v Feb=2 -v Mar=3 -v Apr=4 -v May=5 -v Jun=6 -v Jul=7 -v Aug=8 ' !/^d/ { if(NR>1) {printf "%-29s\t\t%s\t%5s\t\t%s %s,", $9,$1,$5,$`$6`,$7} }' Thanks. (10 Replies)
Discussion started by: manubatham20
10 Replies

6. Shell Programming and Scripting

Problem using variable inside awk

HI, This is the code I am using: awk -v aaa="connect" 'BEGIN {IGNORECASE} /aaa/,/!/ {print NR}' bb This does not throw any error but it does not work. Pls help Thanks. (4 Replies)
Discussion started by: sudvishw
4 Replies

7. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

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

9. Shell Programming and Scripting

Variable assignment inside awk

Hi, Was hoping someone could help with the following: while read line; do pntadm -P $line | awk '{if (( $2 == 00 && $1 != 00 ) || ( $2 == 04 )) print $3,$5}'; done < /tmp/subnet_list Anyone know if it is possible to assign $3 and $5 to separate variables within the {} brackets? Thanks... (14 Replies)
Discussion started by: CiCa
14 Replies

10. UNIX for Beginners Questions & Answers

Variable and awk inside for loop

Thanks all for taking time out and reading this thread and big Thanks to all who have come forward for rescue. Background: I have a variable "nbrofcols" that has number of columns from a data file. Now, using this count in for loop, I am trying to get the maximum length of each column present... (7 Replies)
Discussion started by: svks1985
7 Replies
STIME(2)						     Linux Programmer's Manual							  STIME(2)

NAME
stime - set time SYNOPSIS
#include <time.h> int stime(time_t *t); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): stime(): _SVID_SOURCE DESCRIPTION
stime() sets the system's idea of the time and date. The time, pointed to by t, is measured in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). stime() may only be executed by the superuser. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EFAULT Error in getting information from user space. EPERM The calling process has insufficient privilege. Under Linux the CAP_SYS_TIME privilege is required. CONFORMING TO
SVr4. SEE ALSO
date(1), settimeofday(2), capabilities(7) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2010-02-25 STIME(2)
All times are GMT -4. The time now is 06:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy