Re: Unix script question (basic)
From: those who know me have no need of my name (not-a-real-address_at_usa.net)
Date: 03/06/04
- Previous message: Susan: "Re: stty erase help"
- In reply to: Piestiany7: "Unix script question (basic)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 06 Mar 2004 00:08:18 GMT
in comp.unix.questions i read:
>Some time ago on these boards someone suggested a good
>way of finding out how many columns there were in a file
this is a newsgroup, not a `board'.
>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)
it performs word splitting and assigns the results to the positional
parameters, this should be explained in your shell's documentation.
>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
cat doesn't `look' at anything. if you want to run a command in a loop and
have each iteration obtain subsequent data from a file then the easiest
method is to redirect stdin for the loop, not for any individual command
within the loop, e.g.,
while read x; do set -- $x; echo "columns: $#"; done < "file"
-- a signature
- Previous message: Susan: "Re: stty erase help"
- In reply to: Piestiany7: "Unix script question (basic)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|