Re: shell script
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 07/16/04
- Next message: Allen Kistler: "Re: view file from archive without extracting"
- Previous message: Roger Leigh: "Re: Linux console: unicode_start breaks keyboard input"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Jul 2004 09:43:07 GMT
On 2004-07-16, tibo wrote:
> Hello.
>
> I'm making a shell script that analyse this result of a command :
>
> bridge name bridge id STP enabled interfaces
> bridge0 8000.0090270d3c6a no eth0
>
> eth1
>
> eth2
> bridge1 8000.000000000000 no
>
> On this result, you can see that interface eth0, eth1 and eth2 are
> attached to bridge0 and that bridge1 has not interfaces attached.
>
> I'd like to do this analyse with a script.
>
> I tried with grep and awk stuff. But I have two problems :
>
> 1)
> On first line, "eth0" is in the 4th column
> On second and third lines, "eth1" and "eth2" are on the first column
>
> 2)
> The other problem is that I'd like to do something like :
>
> scan 4th column or 1st colum (to see "eth0", "eth1", "eth2") of each line
> after bridge0 until I meet "bridge1" on first column. But there's no "until"
> loop in shell script !
>
> Does anyone have an idea, some tip to give me ? Thanks a lot for your
> answers.
man bash:
while list; do list; done
until list; do list; done
The while command continuously executes the do list as long as
the last command in list returns an exit status of zero. The
until command is identical to the while command, except that the
test is negated; the do list is executed as long as the last
command in list returns a non-zero exit status. The exit status
of the while and until commands is the exit status of the last
do list command executed, or zero if none was executed.
............
But I don't think that's what you really want.
Try (this is just a skeleton):
<COMMAND> | { read header ## discard first line
while read col1 col2 col3 col4
do
case $col1 in
bridge[0-9]*) : ;;
*) ;;
esac
done
}
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Allen Kistler: "Re: view file from archive without extracting"
- Previous message: Roger Leigh: "Re: Linux console: unicode_start breaks keyboard input"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|