in reply to Re: Shell scripts?
in thread Shell scripts?

wc -l filenamewill do.

pelagic

Replies are listed 'Best First'.
Re: Re: Re: Shell scripts?
by gellyfish (Monsignor) on Apr 30, 2004 at 11:30 UTC

    And if yu really want to do it in Perl that you can always use the Shell module that is standard with Perl:

    use Shell; + my $foo = wc('-l', '.bash_profile'); + print $foo;
    ;-}

    /J\

Re: Re: Re: Shell scripts?
by thor (Priest) on Apr 30, 2004 at 12:07 UTC
    Careful, tiger. wc's behavior differs depending on whether it read from stdin or you passed it a file. Observe:
    thulben@bravo:~
    7$ wc -l file
    10 file
    thulben@bravo:~
    8$ cat file | wc -l
    10
    thulben@bravo:~
    9$
    
    So, to get just the line count, you'd either have to do the cat-pipe thing, or pipe the results to awk.

    thor

      Or to reduce unnecessary forking you can just redirect STDIN:

      wc -l <file

      /J\

      >   wc's behavior differs ?
      $cat file | wc -l 10 $wc -l file 10 file $wc -l < file 10 $
      The output might be formatted differently but the counting remains the same.

      pelagic