Re: scripting question

From: Barry Finkel (b19141@ACHILLES.CTD.ANL.GOV)
Date: Fri May 23 2003 - 11:36:57 EDT


>>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



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