|
Home > Archive > Unix Shell > December 2007 > Removing numbers
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]
|
|
| apogeusistemas@gmail.com 2007-11-29, 7:21 pm |
| 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
| |
| Rikishi 42 2007-11-29, 7:21 pm |
| On 2007-11-29, apogeusistemas@gmail.com <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
| |
| Bill Marcum 2007-11-29, 7:21 pm |
| On 2007-11-29, apogeusistemas@gmail.com <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'.
| |
| Ed Morton 2007-11-29, 7:21 pm |
|
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.
| |
| Michael Tosch 2007-11-29, 7:21 pm |
| Bill Marcum wrote:
> On 2007-11-29, apogeusistemas@gmail.com <apogeusistemas@gmail.com> wrote:
>
> 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
| |
| apogeusistemas@gmail.com 2007-11-29, 7:21 pm |
| On 29 nov, 18:53, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 2007-11-29, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> 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.
| |
| Geoff Clare 2007-12-03, 1:28 pm |
| Michael Tosch wrote:
>
> 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@gclare.org.uk>
|
|
|
|
|