0
i'm just wondering how can we use awk to do exact matches.
for eg
$ cal 09 09 2009
September 2009
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
$ cal 09 09 2009 | awk '{day="9"; col=index($0,day); print col }'
17
0
0
11
20
0
8
0
As you can see the above command outputs the index number of all the lines that contain the string/number "9", is there a way to make awk output index number in only the 4th line of cal output above.??? may be an even more elegant solution?
I'm using awk to get the day name using the cal command. here's the whole line of code:
$ dayOfWeek=$(cal $day $month $year | awk '{day='$day'; split("Sunday Monday Tuesday Wednesday Thursday Friday Saturday", array); column=index($o,day); dow=int((column+2)/3); print array[dow]}')
The problem with the above code is that if multiple matches are found then i get multiple results, whereas i want it to output only one result.
Thanks!
Thanks Matt, but i need to support dates from year 0001 to 9999, date command is no good for these years.. – Jasdeep Singh – 2011-03-07T19:37:51.843
I've just noticed another problem with that command - it set my clock to 09/09/2009 :S – Majenko – 2011-03-07T19:42:40.857
Well, I'm getting stumped. I was thinking of passing it through grep first but that wouldn't work for the first / last numbers on the line. Or would it? Hang on... – Majenko – 2011-03-07T19:51:35.073
Ok, I am editing my answer to have something completely different to what was there... – Majenko – 2011-03-07T20:00:06.247