in reply to Shell scripts?

These are two very different things!
The Shell Scripting is a great language, I love it.
See this site for your learning..
From Learning Perl:
So, the best you can do is stare at a shell script, figure out what it does, and start from scratch with Perl. Of course, you can do a quick-and-dirty transliteration, by putting major portions of the original script inside system() calls or backquotes. You might be able to replace some of the operations with native Perl: for example, replace system(rm fred) with unlink(fred), or a shell for loop with a Perl for loop. But generally you'll find it's a bit like converting a COBOL program into C (with about the same reduction in the number of characters and increase in illegibility).

Second answer:
cat filename | wc -l
on the Unix shell
UPDATE:
or better:
wc -l filename
thanks pelagic

Replies are listed 'Best First'.
Re: Re: Shell scripts?
by pelagic (Priest) on Apr 30, 2004 at 08:27 UTC
    wc -l filenamewill do.

    pelagic

      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\

      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