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

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

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

    Or to reduce unnecessary forking you can just redirect STDIN:

    wc -l <file

    /J\

Re: Re: Re: Re: Shell scripts?
by pelagic (Priest) on Apr 30, 2004 at 12:37 UTC
    >   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