Removing numbers
am 29.11.2007 21:10:16 von apogeusistemas
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
Re: Removing numbers
am 29.11.2007 21:51:32 von Rikishi 42
On 2007-11-29, apogeusistemas@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
Re: Removing numbers
am 29.11.2007 21:53:33 von Bill Marcum
On 2007-11-29, apogeusistemas@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'.
Re: Removing numbers
am 29.11.2007 22:24:11 von Ed Morton
On 11/29/2007 2:10 PM, apogeusistemas@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.
Re: Removing numbers
am 30.11.2007 00:17:40 von Michael Tosch
Bill Marcum wrote:
> On 2007-11-29, apogeusistemas@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 @ hp : com
Re: Removing numbers
am 30.11.2007 01:48:26 von apogeusistemas
On 29 nov, 18:53, Bill Marcum wrote:
> On 2007-11-29, apogeusiste...@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.
Re: Removing numbers
am 03.12.2007 15:01:14 von Geoff Clare
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