Re: Unix script question (basic)
From: Michael Tosch (eedmit_at_NO.eed.SPAM.ericsson.PLS.se)
Date: 03/05/04
- Next message: Ernie Klein: "Re: Help me with Unix on Mac OS X..Trying to install x11/fink/gnome"
- Previous message: Chris F.A. Johnson: "Re: Unix script question (basic)"
- In reply to: Piestiany7: "Unix script question (basic)"
- Next in thread: Stephane CHAZELAS: "Re: Unix script question (basic)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Mar 2004 19:16:45 GMT
In article <20040305134412.10232.00000833@mb-m03.aol.com>, piestiany7@aol.com (Piestiany7) writes:
> Some time ago on these boards someone suggested a good
> way of finding out how many columns there were in a file
>
> read x < $1
> set -- $x
> columns=$#
>
> I have two questions
>
> 1) what effect is set -- $x having (ie in enabling subsequently for $# to have
> meaning)
set sets positional paramenters. The original parameters (arguments passed when
the script was called) are overwritten.
The handling of positional parameters in brief:
$1 is first parameter, $2 is second, ...., and $# is number of paremeters set.
In case $x would start with a -, the set would expect an option. A -- means there
are no further options (analog to rm -- -i which removes the file '-i').
This and more you find in
man sh
>
> 2) if we were to put this into a loop to read every single row in the file and
> output the number of columns, can we use a construct like
> <command> | while read row
>
> if so what can we have for 'command'? cat looks at a field at a time
>
Yes.
cat does nothing on the file contents.
So
cat file | while read row; do; ...; done
works as good as the smarter
while read row; do; ...; done < file
-- Michael Tosch IT Specialist HP Managed Services Germany Phone +49 2407 575 313 Mail: michael.tosch@hp.com
- Next message: Ernie Klein: "Re: Help me with Unix on Mac OS X..Trying to install x11/fink/gnome"
- Previous message: Chris F.A. Johnson: "Re: Unix script question (basic)"
- In reply to: Piestiany7: "Unix script question (basic)"
- Next in thread: Stephane CHAZELAS: "Re: Unix script question (basic)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|