Check the exact month and date


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Check the exact month and date
# 1  
Old 01-02-2013
Check the exact month and date

Hi All,

Please help me in the below code.

Code:
 awk -v pattern="$_month$Day" 'BEGIN {FS = "." }; {if ($3~pattern) {print $0}}' ${BASE_DLY_UOGL_WORK_DIR}/Avail_ApprovedReports.txt > ${BASE_DLY_UOGL_WORK_DIR}/Reqd_ApprovedReports.txt

the above code will take the current month and date (i.e pattern ='0102' and searches in the 3 column (i.e 20130101024056) from the file xx.txt.20130101024056.gz

But the above code works wrongly since today's date is 0102 and it should check 20130101024056 and if there is no match it means there is no file for today.
But it is searching the entire column and if matches it is processing that file.(i.e 20130101024056)
Please help me in the code to check only required month and date (0101) from the 3rd column of the file.

Thanks,
Kiran
# 2  
Old 01-02-2013
Use awk substr function:
Code:
if(substr($3,5,4)==pattern)

# 3  
Old 01-03-2013
Or, extend pattern to contain the year as well: pattern="20130102"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

2. Shell Programming and Scripting

Not able to fetch previous month first date and last date

I am not able to fetch first date and last date previous month date -d -1month +%Y-%m-%d date -d -1month +%Y-%m-%d I need two format dd-mm-yyy previous month 01-03-2016 previous month 31-03-2016 and also only date 1 to 31 Aprriciate your replay (4 Replies)
Discussion started by: jagu
4 Replies

3. Shell Programming and Scripting

Find one month before date

Hi, I want two dates one will be the current date and the other one will be just one month before. Say if current month is 11/4/2014 then the other date should be 11/3/2014. #!/bin/ksh currentDtae=`date` oneMonthBefore= ? I dont know how to do it. Went through some of the related threads... (15 Replies)
Discussion started by: Sharma331
15 Replies

4. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

5. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

6. Shell Programming and Scripting

Delete the files by exact date

we have files created by Aug12 and Feb 23 and Mar10 i want to delete the files which has created on Mar 10 Kindly let me know the script to delete the files which is created by Mar 10 (4 Replies)
Discussion started by: venikathir
4 Replies

7. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

8. Shell Programming and Scripting

Pass the first date and last date of previous month

Hi All, I need to run a job every month at the beginning of the month which is scheduled through autosys, lets say on 03/01/2010. I need to pass the last month's i.e February's first_date = 02/01/2010 and last_date = 02/28/2010 as variables to a stored procedure. Can somebody please pass... (2 Replies)
Discussion started by: vigdmab
2 Replies

9. Shell Programming and Scripting

Get date one month from today

I need to get the date one month in the future from today - or 30 days from today etc... I need this to work all year around - I cannot find anything to solve this issue in the search / faqs etc.... (5 Replies)
Discussion started by: frustrated1
5 Replies

10. Shell Programming and Scripting

yesterday date month/date

Hi expert, I want to retrieve yesterday su log. How to calculate and assign variable value ( 06/23 ) in myVariable ? #!/bin/sh myVariable=yesterday date in month/date cat /var/adm/sulog | grep $myVariable > file.txt many thanks! (5 Replies)
Discussion started by: skully
5 Replies
Login or Register to Ask a Question