Description: $ wc -l README 200 README This is fine for interactive use, but not convenient in shell scripts, because the outpur cannot be easily handles. Many times only the integer value is needed: lines=$(wc -l $file) if [ $lines > $max ]; then # ERROR! ... do something fi SUGGESTION Of course there are various workarounds, but it would be nice to have new option
In this case, I'd suggest simply doing lines=$(wc -l < file) For other cases, it's so trivial to get the first column of whitespace delimited output in unix (or to simply cat some files to stdin and avoid the filename issue) that I just don't see the point. Mike Stone
Hey You can get around this with a pipe : $ cat README | wc -l 3 will just output the linenumber. Hope this helped. Cheers Didi
Hey You can get around this with a pipe : $ cat README | wc -l 3 will just output the linenumber. Hope this helped. Cheers Didi
Jari Aalto wrote: If you don't want the filename displayed just use stdin: lines=$(wc -l <$file) Brian
Didi wrote: That creates an extra cat process. This is undesirable and unnecessary. Search the web for "useless use of cat" for more explanation. http://www.google.com/search?q=useless+use+of+cat+award Better to simply redirect the input as others have suggested. lines=$(wc -l < README) Bob
Jari Aalto <jari.aalto@cante.net> writes: $ wc -l < README 200 Andreas.
Jari Aalto <jari.aalto@cante.net> writes: $ wc -l < README 200 Andreas.
Hey because of readable (KISS). The '<' redirect is often confusing, for many people, especially if the command is built into a script. Because then people are thinking of the term less / greater than. I am aware that this is a point of discussion and if I write something for my personal use I use the '<', but if I write this in production or teaching code some one is going to come into my office and harass me just because he didn't see the ` in my Perl script. I hope this sort of clarifies my way of thinking. Cheers Didi ---- www.cern.ch/ribalba / www.ribalba.de Email / Jabber: ribalba@gmail.com Phone (Work) : +41 22 7679376 Skype : ribalba Address : CERN / IT-FIO-FS / GENEVE 23/ SCHWEIZ
Jari Aalto wrote: Options are bad because of the extra complexity presented to users. Currently wc only suppresses the "total" if only one file is passed. I wonder could we go one step further and suppress the filename also like grep does when passed a single file? Note existing scripts that do the following would continue to work: lines=`wc -l file | cut -d ' ' -f1` It's probably safer though to not change the current operation, considering that the functionality can be satisfied using the above, or the following: lines=`wc -l <file` Pádraig.
Jari Aalto wrote: Options are bad because of the extra complexity presented to users. Currently wc only suppresses the "total" if only one file is passed. I wonder could we go one step further and suppress the filename also like grep does when passed a single file? Note existing scripts that do the following would continue to work: lines=`wc -l file | cut -d ' ' -f1` It's probably safer though to not change the current operation, considering that the functionality can be satisfied using the above, or the following: lines=`wc -l <file` Pádraig.
Pádraig Brady <P@draigBrady.com> writes: That would require adding an option to be comptible with POSIX. Andreas.
Pádraig Brady <P@draigBrady.com> writes: That would require adding an option to be comptible with POSIX. Andreas.
Then they probably shouldn't be programming production shell scripts. That said, you can move things around to make it more obvious at first glance that it's an input: <file wc -l Mike Stone
Hello, Good morning, We have gone through your samples from a partner and Here is our Order List. Please do bear in mind that we are very much in need of this order, quote your competitive prices. Kindly send the Order confirmation. Your early reply will be much appreciated. Best Regards, Maryanah Erwin. PT FINDORA INTERNUSA Jln Pahlawan 66 Kec. Arjawinangun 45162 CIREBON West-Java INDONESIA tel : +62 231 357334 fax: +62 231 357260 email: marketing@findora.com
Good day. Have you already seen the report I sent? Please have a look, the message might not have arrived. https://dvc.team/quasi-eius/nihil.zip-----Original Message-----