awk comparison not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk comparison not working
# 1  
Old 03-31-2013
awk comparison not working

Can you please help me on belw awk comparsion which doest not work

Code:
 
cat employee_list
NAME Last-login
Jack 03/25/2013
Maneul 03/26/2013
Eric 03/26/2013
Samuel 03/28/2013
loak 03/29/2013
zac 03/29/2013

this is my awk .. it gives me error

Code:
cat employee_list | awk '(($2=='date +"%m/%d/%Y" -d last-monday') || ($2=='date +"%m/%d/%Y" -d last-tuesday')) {print $1}'

( date working fine)
Code:
date +"%m/%d/%Y" -d last-monday
03/25/2013

output example

Code:
Jack
Maneul
Eric


Last edited by Scrutinizer; 03-31-2013 at 04:35 AM.. Reason: changed icode tags to code tags
# 2  
Old 03-31-2013
The date is a string, so in awk there would need to be double quotes around them if you want to compare it do $2. Although that would work, it would be better to use awk variables (for example through the -v mechanism) to be able to use shell values inside awk..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 03-31-2013
Code:
awk '$2==d1 || $2==d2 {print$1}' d1="$(date +"%m/%d/%Y" -d last-monday)" d2="$(date +"%m/%d/%Y" -d last-tuesday)" employee_list
Jack
Maneul
Eric

This User Gave Thanks to Jotne For This Post:
# 4  
Old 04-01-2013
Code:
while read nm dt; do [ "$dt" == "$(date -d "last-monday" +"%m/%d/%Y")" -o "$dt" == "$(date -d "last-tuesday" +"%m/%d/%Y")" ] && echo $nm; done < employee_list

This User Gave Thanks to balajesuri For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk IF date comparison help

Hey everyone, I'm trying to create a script using awk and if that will list all of our aws tapes that have archived date that is past 90 days from todays current date, so that I can pass that to my aws command to remove. The fifth column is the creation date in epoch/seconds, so I'm... (13 Replies)
Discussion started by: beyondmondays
13 Replies

2. Shell Programming and Scripting

awk comparison of dates

I need to use awk to return lines in multiple files that contain a date between a start date and end date. The format of the date is as seen in column 3 in the following line. A,1458147240,Mar 30 2015 12:54:00PM,s15u4chn ,2,GPS Major Alarm `clear`,component.Channel,10,15,0,138,183,,,Mar 16... (4 Replies)
Discussion started by: randman1
4 Replies

3. Shell Programming and Scripting

Python: Comparison is not working for me

Guys it is very simple script , but for some reason my IF condition is not matching. from sys import argv import os filename='testdata.txt' txt=open(filename) while 1: line= txt.readline() if not line: break line=line.strip('\n') sp=line.split(" ") command =sp+ " " +sp+ " "... (4 Replies)
Discussion started by: baker
4 Replies

4. Shell Programming and Scripting

Need help with simple comparison in AWK

Hi, I'm new to AWK and I'm having problems comparing a field to a string variable. /ARTIST/ {x = $2} $1 ~ x {print $0}My code tries to find a record with the string "ARTIST". Once it finds it, it stores the second field of the record into a variable. I don't know what the problem is for the... (7 Replies)
Discussion started by: klusps
7 Replies

5. Shell Programming and Scripting

File comparison using awk

my files are as follows fileA sepearated by tab /t 00 lieferungen 00 attractiop 01 done 02 forness 03 rasp 04 alwaysisng 04 funny 05 done1 fileB funnymou120112 funnymou234470 mou3raspnhdhv rddfgmoudone1438748 so all those record which are greater than 3 and which are not... (6 Replies)
Discussion started by: rajniman
6 Replies

6. Shell Programming and Scripting

awk comparison and substitution

Hi, here's my - not so easy to describe - problem: I want to compare the values of one file (FileA) with a cutoff-value and, if this comparison is true, substitute those values with those in the second file (FileB). However, there are many FileA's (FileA), whereas there is only one FileB. Every... (10 Replies)
Discussion started by: waddle
10 Replies

7. Shell Programming and Scripting

string comparison not working inside while loop

The string comparison highlighted below is not working fine. Please help: while read line do # Get File name by deleting everything that preceedes and follows Filename as printed in cvs status' output f_name=`echo $line | sed -e 's/^File://' -e 's/ *Status:.*//' | awk '{print $NF}'` ... (4 Replies)
Discussion started by: sudvishw
4 Replies

8. Shell Programming and Scripting

String comparison not working inside while loop

Hi, In the code included below, the string comparision is not working fine. Please help while (( find_out >= i )) do file=`head -$i f.out|tail -1` dir=`dirname $file` cd $dir Status="" if ; then Status=`cvs -Q status... (3 Replies)
Discussion started by: sudvishw
3 Replies

9. Shell Programming and Scripting

awk comparison

Hello all, Probably a very simple question, I am stuck with a small part of a code: I am trying to do a comparison to get the maximum value of column 6 if columns 1, 4 and 5 of two or more rows match. Here is what I am doing: awk -F'\t' '{if ($6 > a)a=$6}END{for (i in a) print i"\t"a}' ... (4 Replies)
Discussion started by: jaysean
4 Replies

10. Shell Programming and Scripting

Comparison and editing of files using awk.(And also a possible bug in awk for loop?)

I have two files which I would like to compare and then manipulate in a way. File1: pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2: pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2... (1 Reply)
Discussion started by: linuxkid
1 Replies
Login or Register to Ask a Question