Re: Unix script question (basic)
From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 03/05/04
- Next message: Bill Marcum: "Re: argument parser parsing my double quotes"
- Previous message: Tim Haynes: "Re: Unix Memory Question"
- In reply to: Piestiany7: "Unix script question (basic)"
- Next in thread: those who know me have no need of my name: "Re: Unix script question (basic)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 5 Mar 2004 22:10:20 +0100
2004-03-05, 18:44(+00), Piestiany7:
> 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=$#
That's not correct.
It should be:
set -f
set x `head -1 < "$1"`
shift
columns=$#
(otherwise, there's backslash processing and filename
generation).
or (less portable):
read -r x < "$1"
set -f
set -- $x
columns=$#
Best is probably:
columns=`awk '{exit}END{print NF}' < "$1"`
-- Stéphane ["Stephane.Chazelas" at "free.fr"]
- Next message: Bill Marcum: "Re: argument parser parsing my double quotes"
- Previous message: Tim Haynes: "Re: Unix Memory Question"
- In reply to: Piestiany7: "Unix script question (basic)"
- Next in thread: those who know me have no need of my name: "Re: Unix script question (basic)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]