Removing numbers

Hi:

I have one script with this:

LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31"

echo "please enter weekend days: " 5 6 12 13 20 21 28 29

How could I remove weekdays from LA list in a script ?

Thanks
apogeusistemas [ Do, 29 November 2007 21:10 ] [ ID #1881360 ]

Re: Removing numbers

On 2007-11-29, apogeusistemas [at] gmail.com <apogeusistemas [at] gmail.com> wrote:
> Hi:
>
> I have one script with this:
>
> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31"
>
> echo "please enter weekend days: " 5 6 12 13 20 21 28 29
>
> How could I remove weekdays from LA list in a script ?
Sorry I can't give you a straight answer.

But... if your aim is to build a list of weekdays for a given month,
wouldn't it be better to do have a script generate it, instead of asking for
a week-end input?

I'd say scripting a loop to run from 1 until the month changes should be
feasable. And you'd only add the day to your LA line if it's a weekday.

Don't feel comfortable enough with shell scripting to write it for you, but
you know what I mean...



--
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams
Rikishi 42 [ Do, 29 November 2007 21:51 ] [ ID #1881362 ]

Re: Removing numbers

On 2007-11-29, apogeusistemas [at] gmail.com <apogeusistemas [at] gmail.com> wrote:
>
>
> Hi:
>
> I have one script with this:
>
> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31"
>
> echo "please enter weekend days: " 5 6 12 13 20 21 28 29
>
> How could I remove weekdays from LA list in a script ?
>
> Thanks

echo "please enter weekend days: "; read weekend_days
grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo $LA |tr ' ' '\n')

Or instead of asking the user what days are weekends, you could parse
the output of 'cal'.
Bill Marcum [ Do, 29 November 2007 21:53 ] [ ID #1881363 ]

Re: Removing numbers

On 11/29/2007 2:10 PM, apogeusistemas [at] gmail.com wrote:
> Hi:
>
> I have one script with this:
>
> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31"
>
> echo "please enter weekend days: " 5 6 12 13 20 21 28 29
>
> How could I remove weekdays from LA list in a script ?
>

Are you asking how to remove the numbers that the user inputs from the list you
have in your variable or how to get remove the set of weekdays from your
variable without user input? If the latter, is that really what you want? It'd
leave you with day numbers that may not exist in a given month. You should
provide some more information before you get all sorts of interpretations...

Ed.
Ed Morton [ Do, 29 November 2007 22:24 ] [ ID #1881365 ]

Re: Removing numbers

Bill Marcum wrote:
> On 2007-11-29, apogeusistemas [at] gmail.com <apogeusistemas [at] gmail.com> wrote:
>>
>> Hi:
>>
>> I have one script with this:
>>
>> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
>> 23 24 25 26 27 28 29 30 31"
>>
>> echo "please enter weekend days: " 5 6 12 13 20 21 28 29
>>
>> How could I remove weekdays from LA list in a script ?
>>
>> Thanks
>
> echo "please enter weekend days: "; read weekend_days
> grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo $LA |tr ' ' '\n')

The two <( ) is really an amazing construct!
I found it works in Posix shells.

fgrep -vxf <(printf "%02d\n" $weekend_days) <(printf "%02d\n" $LA)

will also pad the numbers with 0.
fgrep -vxf is generally safer than the regular expression with grep -vf

>
> Or instead of asking the user what days are weekends, you could parse
> the output of 'cal'.

This could be

cal |
awk 'NR>2{for(i=1;i<=4;i++)if((day=substr($0,i*3+1,2)+0)>0)printf "%02d\n",day}'


--
Michael Tosch [at] hp : com
Michael Tosch [ Fr, 30 November 2007 00:17 ] [ ID #1882408 ]

Re: Removing numbers

On 29 nov, 18:53, Bill Marcum <marcumb... [at] bellsouth.net> wrote:
> On 2007-11-29, apogeusiste... [at] gmail.com <apogeusiste... [at] gmail.com> wrote:
>
>
>
> > Hi:
>
> > I have one script with this:
>
> > LA=3D"01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> > 23 24 25 26 27 28 29 30 31"
>
> > echo "please enter weekend days: " 5 6 12 13 20 21 28 29
>
> > How could I remove weekdays from LA list in a script ?
>
> > Thanks
>
> echo "please enter weekend days: "; read weekend_days
> grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo $LA |tr ' ' '\n')
>
> Or instead of asking the user what days are weekends, you could parse
> the output of 'cal'.

Thank You, Bill, your script works fine to me.
I=B4ll use to remove weekdays and holidays.
apogeusistemas [ Fr, 30 November 2007 01:48 ] [ ID #1882410 ]

Re: Removing numbers

Michael Tosch wrote:

>> grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo $LA |tr ' ' '\n')
>
> The two <( ) is really an amazing construct!
> I found it works in Posix shells.

It works in _some_ POSIX shells. It's not mandated by POSIX.

--
Geoff Clare <netnews [at] gclare.org.uk>
Geoff Clare [ Mo, 03 Dezember 2007 15:01 ] [ ID #1884295 ]
Linux » comp.unix.shell » Removing numbers

Vorheriges Thema: simple ksh program
Nächstes Thema: [\D\S] vs. [^\d\s]