The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 05-31-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
Shell_Life, akrathi, anbu23, it seems that your solutions do not work in all the cases :

Code:
$ cal 12 2007
       December 2007      
Sun Mon Tue Wed Thu Fri Sat  
                         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  31

$ cal 12 2007 | tail +3 | cut -c16,17 | sed '/^ *$/d' | sed -n '3p'
 2
$ cal 12 2007 | cut -c16-18 | tail -4 | head -1
 13
$ cal 12 2007 | sed -n "5{s/ *[0-9]\{2\}$//;s/^.* //p;}"
14
$

A possible solution :

Code:
$ cal 12 2007 | awk 'NR>2 && NF>=2 && ++w==3 {print $6}'
21
$ cal 07 2007 | awk 'NR>2 && NF>=2 && ++w==3 {print $6}'
20
$ cal 6 02007 | awk 'NR>2 && NF>=2 && ++w==3 {print $6}' 
15
$

Jean-Pierre.