Advice on using awk in ksh with system date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Advice on using awk in ksh with system date
# 1  
Old 03-11-2010
Advice on using awk in ksh with system date

OK I have a simple awk script:
Code:
$ awk '/03\/11\/10/' foofile|awk -f finderrors.awk

I want to use in the ksh script to so that I can do something like this:

Code:
#!/bin/ksh
TODAY=`date +"%D"`
awk /$TODAY/ foofile|awk -f finderrors.awk

The problem I am having is (I believe) is with the special characters in $TODAY, namely the forward slashes in the date.

I will eventually make it so the script will use today's date if no date argument is passed.

But for now I just want to use today's date. Is my only hope to edit the date and add the "\" in front of the "/"?

Thanks.

BTW: My first post here.. so forgive my newbie mistakes Smilie
# 2  
Old 03-11-2010
try:
Code:
grep  "$TODAY" foofile|awk -f finderrors.awk

# 3  
Old 03-11-2010
Just proof that I was stuck in a loop in my head trying to pass the date to awk!! thanks.
# 4  
Old 03-11-2010
or pass the date to finderrors.awk and change the script to filter anything OTHER than the passed date.
Code:
#!/bin/ksh
TODAY=`date +"%D"`
awk -f finderrors.awk d="${TODAY}" foofile

finderrors.awk:
Code:
BEGIN {
  # whatever
}
$0 ~ d {
     # do the deed
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Need advice about ksh literature

Hi guys Can you recommend a good book for absolute beginner. I bought KSH93 by David Korn but I don't like it. It's not user-friendly. I need book with easy examples and some exercises. Can be a video lectures too. Thanks. (1 Reply)
Discussion started by: solaris_user
1 Replies

4. UNIX for Dummies Questions & Answers

Becoming a system administrator, need some advice.

I've been learning linux and solaris for the past couple months and have been thinking about seeking a systems admin career. Is it worth it to learn solaris? Do many companies really use it or is it a waste of my time? Would learning just linux be a better idea? I see there's more opportunity as a... (2 Replies)
Discussion started by: austinramsay
2 Replies

5. UNIX for Dummies Questions & Answers

Need Some Advice - Best Distro For My System

Hey guys, this is my first time posting here (although I've been reading the forums for a while now). I'm looking for a good UNIX (or UNIX based/UNIX-like) distro to install on an old Dell Dimension 2400 Destop. I've done ALOT of research on the different distros and I've tried a few out but I... (6 Replies)
Discussion started by: Pyramist
6 Replies

6. HP-UX

Advice on HP-UX system backups

Hello, forgive me if this seems a bit trivial to you but I am fairly new to HP-ux having worked with AIX for the past 15 years. We have inherited a couple of HP-ux servers without any tape drives and running Hp-ux v11. I am familiar with creating mksysbs on our AIX Nim server for recovery and... (12 Replies)
Discussion started by: neilh1703
12 Replies

7. Shell Programming and Scripting

csv file field needs to be changed current system date with awk

HI, I have csv file with records as shown below. 4102,Bangalore,G10,21,08/17/2011 09:28:33:188,99,08/17/2011 09:27:33:881,08/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

8. UNIX for Dummies Questions & Answers

Use of system date in awk

i'm facing problems in using system date in a awk script... it should display the date in a report in mm/dd/yy format.. please help me in this case.. thanks (3 Replies)
Discussion started by: Manish4
3 Replies

9. UNIX for Dummies Questions & Answers

using system date in awk

hi, I'm getting some issues while running below awk:- I want to use the system date to get pritned on the report but not getting it please help in this case BEGIN { sysdate = substr($date,5,6) print "WEA\t\t\t\t\t\t\t\t\t\tCLAIM AND APPROVAL REPORT" print "REPORT RUN DATE:",$sysdate... (1 Reply)
Discussion started by: Manish4
1 Replies

10. Shell Programming and Scripting

awk system date with -d option

Hi I get problems when using the following command : cat logs | awk -F";" '{ system("date -d "1970-01-01 UTC+0100 $1 seconds""); }' date: date invalide `1968641199401200' date: date invalide `1968641199381709' this is what i have in my log file : cat logs 1199401200;a... (3 Replies)
Discussion started by: arag0rn
3 Replies
Login or Register to Ask a Question