Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #266255

Re: counting commas

From <tomas@tuxteam.de>
Newsgroups linux.debian.user
Subject Re: counting commas
Date 2024-01-19 09:10 +0100
Message-ID <HXS6R-465v-1@gated-at.bofh.it> (permalink)
References <HXRkt-45zk-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Jan 19, 2024 at 07:10:51AM +0000, fxkl47BF@protonmail.com wrote:
> why doesn't grep count 2 commas
> 
> 
> echo 'Kích thước máy xay cỏ, giá máy thế nào , phụ tùng máy mua ở đâu' | grep -c ,
> 1
> 
> echo 'Kích thước máy xay cỏ, giá máy thế nào , phụ tùng máy mua ở đâu' | cut -d, -f1
> Kích thước máy xay cỏ
> 
> echo 'Kích thước máy xay cỏ, giá máy thế nào , phụ tùng máy mua ở đâu' | cut -d, -f2
>   giá máy thế nào
> 
> echo 'Kích thước máy xay cỏ, giá máy thế nào , phụ tùng máy mua ở đâu' | cut -d, -f3
>   phụ tùng máy mua ở đâu

It is in the man page:

   -c, --count
         Suppress  normal output; instead print a count of matching lines
         for each input file.  With the -v,  --invert-match  option  (see
         below), count non-matching lines.

It counts matching lines. You gave it one line.

If you want to go character-wise, tr might fit the bill (e.g. do a tr -c
to remove everything except comma, then measure the resulting string's
length).

Of course, if you have something else than shell+utils there might be
more efficient ways.

Cheers
-- 
t

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

counting commas fxkl47BF@protonmail.com - 2024-01-19 08:20 +0100
  Re: counting commas John Crawley <john@bunsenlabs.org> - 2024-01-19 08:30 +0100
  Re: counting commas <tomas@tuxteam.de> - 2024-01-19 09:10 +0100
  Re: counting commas "Thomas Schmitt" <scdbackup@gmx.net> - 2024-01-19 09:30 +0100
    Re: counting commas Michael Grant <mgrant@grant.org> - 2024-01-19 12:20 +0100
    Re: counting commas Greg Wooledge <greg@wooledge.org> - 2024-01-19 13:40 +0100
      Re: counting commas "Thomas Schmitt" <scdbackup@gmx.net> - 2024-01-19 16:30 +0100
        Re: counting commas fxkl47BF@protonmail.com - 2024-01-19 16:40 +0100
          Re: counting commas Greg Wooledge <greg@wooledge.org> - 2024-01-19 17:50 +0100
            Re: counting commas fxkl47BF@protonmail.com - 2024-01-19 18:30 +0100
            Re: counting commas debian-user@howorth.org.uk - 2024-01-19 18:30 +0100
              Re: counting commas John Hasler <john@sugarbit.com> - 2024-01-19 21:10 +0100
                Re: counting commas Nicholas Geovanis <nickgeovanis@gmail.com> - 2024-01-20 04:00 +0100
                Re: counting commas Nicholas Geovanis <nickgeovanis@gmail.com> - 2024-01-20 05:00 +0100
              Re: counting commas David Wright <deblis@lionunicorn.co.uk> - 2024-01-20 00:10 +0100
                Re: counting commas Cindy Sue Causey <butterflybytes@gmail.com> - 2024-01-20 01:10 +0100
                Re: counting commas Peter Hillier-Brook <phb@hbsys.plus.com> - 2024-01-20 01:10 +0100
                Re: counting commas Curt <curty@free.fr> - 2024-01-20 18:20 +0100
                Re: counting commas Greg Wooledge <greg@wooledge.org> - 2024-01-20 18:30 +0100
                Re: counting commas fxkl47BF@protonmail.com - 2024-01-20 18:40 +0100
                Re: counting commas Curt <curty@free.fr> - 2024-01-20 18:40 +0100
                Re: counting commas David Wright <deblis@lionunicorn.co.uk> - 2024-01-20 21:10 +0100
        Re: counting commas Nicholas Geovanis <nickgeovanis@gmail.com> - 2024-01-20 03:50 +0100
          Re: counting commas gene heskett <gheskett@shentel.net> - 2024-01-20 06:50 +0100
          Re: counting commas gene heskett <gheskett@shentel.net> - 2024-01-20 07:00 +0100
          Re: counting commas "Roy J. Tellason, Sr." <roy@rtellason.com> - 2024-01-20 21:40 +0100
            Re: counting commas gene heskett <gheskett@shentel.net> - 2024-01-20 22:10 +0100
            Re: counting commas John Hasler <john@sugarbit.com> - 2024-01-21 01:10 +0100
              Re: counting commas gene heskett <gheskett@shentel.net> - 2024-01-21 01:20 +0100
                Re: counting commas John Hasler <john@sugarbit.com> - 2024-01-21 01:30 +0100
                Re: counting commas gene heskett <gheskett@shentel.net> - 2024-01-21 02:10 +0100

csiph-web