Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: Using Perl saves time....

by hakkr (Chaplain)
on Jul 18, 2005 at 16:21 UTC ( #475802=note: print w/replies, xml ) Need Help??

in reply to Re: Using Perl saves time....
in thread Using Perl saves time....

more than one nix way to do it ;)
'nl *'
update removed redundant cat *

Replies are listed 'Best First'.
Re^3: Using Perl saves time....
by TomDLux (Vicar) on Jul 18, 2005 at 17:55 UTC

    nl - the line numbering utility takes one or more file names on its command line. So nl * cats the contents of all the files with line numers.

    46$ ls | wc 15 15 233 47$ nl * | wc 857 3540 29899 48$ ls | nl 1 Makefile 2 RCS 3 Tests 4 ... 15

    But you just want the count, not the list, so you would need to | tail -1 | cut -d' ' -f1.

    Or to be precise: ls | nl | tr -s ' ' ' ' | tr "\t" ' ' | cut -d' ' -f2


Re^3: Using Perl saves time....
by chb (Deacon) on Jul 19, 2005 at 08:56 UTC
    Hm, I think with this glob the shell will first try to put all filenames on your commandline. If you have a lot of files, the maximum size for a command line will be exceeded (this maximum can be pretty large on *nix machines, but the OP intended to count lots of files...).

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://475802]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-02-08 07:35 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (40 votes). Check out past polls.