Unix Shell - Command to extract saturdays and sundays

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > Command to extract saturdays and sundays





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Command to extract saturdays and sundays
apogeusistemas@gmail.com

2007-12-22, 1:30 pm

Hi:

I=B4m looking for a command to show me all saturdays and sundays in a
specified month. I create this command using awk, but awk change "cal"
output:

# cal 11 2007 | awk '{ print $1,
$7 }'
November
S S
1
4 10
11 17
18 24
25


# cal 11
2007
November 2007
S M Tu W Th F S
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 11 2007 | awk '{ print $1, $2, $3, $4, $5,
$6,$7 }'
November 2007
S M Tu W Th F S
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


Thanks for your help.

Janis Papanagnou

2007-12-22, 1:30 pm

apogeusistemas@gmail.com wrote:
> Hi:
>
> I´m looking for a command to show me all saturdays and sundays in a
> specified month. I create this command using awk, but awk change "cal"
> output:
>
> # cal 11 2007 | awk '{ print $1,
> $7 }'
> November
> S S
> 1
> 4 10
> 11 17
> 18 24
> 25
>
>
> # cal 11
> 2007
> November 2007
> S M Tu W Th F S
> 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 11 2007 | awk '{ print $1, $2, $3, $4, $5,
> $6,$7 }'
> November 2007
> S M Tu W Th F S
> 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
>
>
> Thanks for your help.
>



Awk operates on fields if you use $1, $2, etc, not on character columns
of data. Use a tool that works on columns like cut (tail to skip header)

cal 01 2007 | cut -c1-3,19-20 | tail +2

Or if you want to use awk use the substr() function (NR and NF to skip
header and empty lines)

cal 01 2007 | awk 'NR>1 && NF {print substr($0,1,2), substr($0,19,2)}'


Janis
Harry331

2007-12-22, 7:26 pm

apogeusistemas@gmail.com wrote...
>
>Hi:
>
>I=B4m looking for a command to show me all saturdays and sundays in a
>specified month. I create this command using awk, but awk change "cal"
>output:
>
># cal 11 2007 | awk '{ print $1,
>$7 }'
>November
>S S
>1
>4 10
>11 17
>18 24
>25


$ cal -m 11 2007 | cut -c15- | tail +2
Sa Su
3 4
10 11
17 18
24 25

Junmin H.

2007-12-23, 1:38 am

On Sat, 22 Dec 2007 22:16:02 +0000, Harry331 wrote:

> apogeusistemas@gmail.com wrote...
>
> $ cal -m 11 2007 | cut -c15- | tail +2
> Sa Su
> 3 4
> 10 11
> 17 18
> 24 25


Should it be

$ cal -m 11 2007 | cut -c15- | tail -n+2

cause tail +2 would get a "cannot open file" error.

junmin@thinking ~ $ cal -m 1 2007 | cut -c 15-| tail +2
tail: cannot open `+2' for reading: No such file or directory


???

junmin

--
Posted via a free Usenet account from http://www.teranews.com

Bill Marcum

2007-12-23, 1:38 am

On 2007-12-23, Junmin H. <tienchi@gmail.com> wrote:
>
>
> Should it be
>
> $ cal -m 11 2007 | cut -c15- | tail -n+2
>
> cause tail +2 would get a "cannot open file" error.
>
> junmin@thinking ~ $ cal -m 1 2007 | cut -c 15-| tail +2
> tail: cannot open `+2' for reading: No such file or directory
>

The -n was not required in older versions of tail and head.
Rakesh Sharma

2007-12-24, 7:33 am


cal 01 2007 |
sed -e '
/[^0-9 ]/{
/[^a-zA-Z ]/b
}

:pad
s/^.\{1,19\}$/& /
tpad

s/^\(..\).*\(..\)$/\1 \2/
'




On Dec 22, 7:51 pm, apogeusiste...@gmail.com wrote:
> Hi:
>
> I=B4m looking for a command to show me all saturdays and sundays in a
> specified month. I create this command using awk, but awk change "cal"

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com