Find week of the year for given date using date command inside awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find week of the year for given date using date command inside awk
# 8  
Old 05-20-2014
Quote:
Originally Posted by clx
Ok, sorry for misunderstanding. In that case, even if it works, system returns the exit status for the command. Its not preferred to store the output.

cnamejj's solution is off course preferable, in case you dont have those built-ins,

Code:
awk ' BEGIN { 
                rt_date="2014-04-20"
                cmd="date -d "rt_date" +%-V"
                cmd | getline week
                print week
}'

Hi Clx,

Perfect, worked seemlessly... thanks a lot...SmilieSmilie

Vijai

---------- Post updated at 04:17 AM ---------- Previous update was at 04:12 AM ----------

Quote:
Originally Posted by clx
Quoting variables wont interpolate them. They would be treated like literal string.

Try
Code:
dinfo = mktime(year FS month FS day" 12 00 00")

Hi cnamejj,

Fantastic.... It worked very well...

Code:
[root@vijrajam-172-20-115-37-unicorn bin]# gawk 'BEGIN {year=2014;month=05;day=20; dinfo = mktime(year FS month FS day " 12 00 00"); wno = strftime("%-V", dinfo); print wno; }'
21

one final question.. which is the best/optimized way to use whether its ur solution or clx's solution...??
Login or Register to Ask a Question

Previous Thread | Next Thread

7 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

How to find all files other than first two dates & last date per month and year?

how to find all files other than first two dates & last date per month and year Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg ... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

3. Shell Programming and Scripting

Help in using date command inside awk

Hi All, bash-3.2$ autorep -J BOX_NAME% -l0 | grep BOX_NAME| awk -f awkScript.awk sh: -c: line 0: unexpected EOF while looking for matching `"' sh: -c: line 1: syntax error: unexpected end of file BOX_NAME SU 06/21/2013 03:44:03 06/21/2013 07:46:37 0 #My awkfile { ... (3 Replies)
Discussion started by: ddspark
3 Replies

4. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

5. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

6. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

7. UNIX for Dummies Questions & Answers

How to find Day of the Week from the given date (Perl)?

How to find the Day of the Week of the given Date using perl? If I have a date in YYY--MM-DD format, how to find the DOW? Based on that, I need to find the following sunday. Pls help. (5 Replies)
Discussion started by: deepakwins
5 Replies
Login or Register to Ask a Question