Sponsored Content
Top Forums Shell Programming and Scripting comparing variables to date as string Post 302599733 by Sara_84 on Saturday 18th of February 2012 07:10:47 AM
Old 02-18-2012
comparing variables to date as string

I have a file

Code:
$ cat myfile
A 02/16/2012
B 02/19/2012
C 02/20/2012
D 02/17/2012
E 02/16/2012

My simple script
Code:
> cat myscript.sh
 
mydate="02/16/2012"
awk ' ($2~/$mydate/) {print $1}' < myfile

but I got no output! and when I try $2~/'$mydate'/

I got: The error context is
Code:
                 >>>  ($2~/02/16/2012/) <<<

I need your help please

Last edited by Scott; 02-18-2012 at 08:31 AM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

comparing variables

I have searched and found a few threads that have dealt with this, but the examples I've tried haven't seemed to help. I am monitoring our database log for high checkpoints. I can parse out the checkpoint value which can be anywhere from zero into a 3 digit number. I set a variable to be the... (3 Replies)
Discussion started by: MizzGail
3 Replies

2. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

3. Shell Programming and Scripting

Comparing two variables

Script #!/bin/sh hardware=PC os=WindowsNET for i in `cat newservers` do x=`sudo /opt/openv/netbackup/bin/admincmd/bpplclients |grep $i |head -40 |grep $i|awk '{print $3;exit}'` if then echo "$i is already added" else echo "Need to add" fi done O/p in debug mode bash-2.05$... (3 Replies)
Discussion started by: rajip23
3 Replies

4. UNIX for Dummies Questions & Answers

comparing 2 string variables in unix

search=Jul 22 date=Jul 22 if then echo They match >>this piece of code does not detect that search and date are equivalent strings.. what's wrong with it? (17 Replies)
Discussion started by: katdaniel16
17 Replies

5. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

6. Shell Programming and Scripting

Comparing String with Number variables

I have two variables and want to perform some functions after comparison $cat file1 14.abcde a=`cut -f 1 -d "." file1 b=15 if then .... fi but i got an error message says that unary operator expected and i think its because of $a is a string and trying to compare with... (3 Replies)
Discussion started by: bonosungho
3 Replies

7. UNIX for Dummies Questions & Answers

comparing variables

im trying to compare ipaddresses. i loop through an array to see if the ip is already is in the array and if it is it should set a flag and then i wont add it to the array. but its just adding all the ipaddresses to the array if ] then ... (3 Replies)
Discussion started by: magnia
3 Replies

8. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

9. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

10. Shell Programming and Scripting

Comparing two variables

I have a script like this. Just couldn't get the comparison part work. Any thought? thanks, #!/usr/bin/ksh -x STEP=`echo $(basename $0 .ksh) | tr "" ""` log=/skip.log while read LINE do if then echo `date`: STEP $STEP skipped by user >> $log exit 0 fi done < $1 echo... (0 Replies)
Discussion started by: ghostmic
0 Replies
TPAGE(1)						User Contributed Perl Documentation						  TPAGE(1)

NAME
Template::Tools::tpage - Process templates from command line USAGE
tpage [ --define var=value ] file(s) DESCRIPTION
The tpage script is a simple wrapper around the Template Toolkit processor. Files specified by name on the command line are processed in turn by the template processor and the resulting output is sent to STDOUT and can be redirected accordingly. e.g. tpage myfile > myfile.out tpage header myfile footer > myfile.html If no file names are specified on the command line then tpage will read STDIN for input. The "--define" option can be used to set the values of template variables. e.g. tpage --define author="Andy Wardley" skeleton.pm > MyModule.pm See Template for general information about the Perl Template Toolkit and the template language and features. AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> VERSION
2.68, distributed as part of the Template Toolkit version 2.19, released on 27 April 2007. COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
ttree perl v5.16.3 2012-01-13 TPAGE(1)
All times are GMT -4. The time now is 07:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy