Re: scripting question

From: Thierry ITTY (thierry.itty@BESANCON.ORG)
Date: Fri May 23 2003 - 12:08:41 EDT


wc return a formatted result with blanks

do

[ "$(( $(wc -l < file) + 0 ))" -eq "22" ] || exit
whatever...

$(wc -l < file) will return the formatted line count
$(( ... + 0 )) will consider this as a number by adding 0 thus removing blanks
[ ... -eq "22" ] will test this as a standard shell string comparison
... || exit will exit if false

hth

A 10:36 23/05/2003 -0500, vous avez écrit :
>>>Is it possible to write a one line command that will test whether a file
>>>contains a specific number of lines, returning 0 if it dies, 1 if it
doesn't
>>>
>>>I've been playing around with wc and test with no luck.
>
>> if [ `cat file | wc -l` -eq 22 ]
>> then
>> whatever
>> fi
>
>As "wc-l" returns a count and a filename, I always use
>
> `wc -l | cut -c1-8`
>
>to get the numeric piece and ignore the filename. In the scripts I
>have written, I have never had a problem with the leading blanks in
>the count field. Someone else suggested
>
> awk '{print $1}'
>
>which will also omit the filename (and which may be a better method
>than mine).
>----------------------------------------------------------------------
>Barry S. Finkel
>Computing and Instrumentation Solutions Division
>Argonne National Laboratory Phone: +1 (630) 252-7277
>9700 South Cass Avenue Facsimile:+1 (630) 252-4601
>Building 222, Room D209 Internet: BSFinkel@anl.gov
>Argonne, IL 60439-4828 IBMMAIL: I1004994
>
>
                        - * - * - * - * - * - * -
Bien sûr que je suis perfectionniste !
Mais ne pourrais-je pas l'être mieux ?
        Thierry ITTY
eMail : Thierry.Itty@Besancon.org FRANCE



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:51 EDT