#469525 coreutils: [wc] RFC: Add option --no-filename

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
Jari Aalto
Date:
2021-10-12 18:12:05 UTC
Severity:
wishlist
#469525#5
Date:
2008-03-05 17:32:38 UTC
From:
To:
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

#469525#10
Date:
2008-03-05 17:47:55 UTC
From:
To:
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

#469525#15
Date:
2008-03-05 20:16:28 UTC
From:
To:
Hey

You can get around this with a pipe :

$ cat README | wc -l
3

will just output the linenumber.

Hope this helped.

Cheers Didi

#469525#20
Date:
2008-03-05 20:16:28 UTC
From:
To:
Hey

You can get around this with a pipe :

$ cat README | wc -l
3

will just output the linenumber.

Hope this helped.

Cheers Didi

#469525#25
Date:
2008-03-05 20:43:26 UTC
From:
To:
Jari Aalto wrote:

If you don't want the filename displayed just use stdin:

lines=$(wc -l <$file)

Brian

#469525#30
Date:
2008-03-05 21:26:27 UTC
From:
To:
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

#469525#35
Date:
2008-03-05 22:15:51 UTC
From:
To:
Jari Aalto <jari.aalto@cante.net> writes:

$ wc -l < README
200

Andreas.

#469525#40
Date:
2008-03-05 22:15:51 UTC
From:
To:
Jari Aalto <jari.aalto@cante.net> writes:

$ wc -l < README
200

Andreas.

#469525#45
Date:
2008-03-06 08:12:40 UTC
From:
To:
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

#469525#50
Date:
2008-03-06 09:38:08 UTC
From:
To:
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.

#469525#55
Date:
2008-03-06 09:38:08 UTC
From:
To:
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.

#469525#60
Date:
2008-03-06 10:51:18 UTC
From:
To:
Pádraig Brady <P@draigBrady.com> writes:

That would require adding an option to be comptible with POSIX.

Andreas.

#469525#65
Date:
2008-03-06 10:51:18 UTC
From:
To:
Pádraig Brady <P@draigBrady.com> writes:

That would require adding an option to be comptible with POSIX.

Andreas.

#469525#70
Date:
2008-03-06 11:59:59 UTC
From:
To:
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

#469525#75
Date:
2021-09-22 04:26:56 UTC
From:
To:
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

#469525#80
Date:
2021-10-12 12:33:10 UTC
From:
To:
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-----