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


Groups > gnu.bash.bug > #12064

Re: count

Path csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: count
Date Mon, 21 Dec 2015 09:28:21 -0500
Lines 49
Approved bug-bash@gnu.org
Message-ID <mailman.305.1450708112.843.bug-bash@gnu.org> (permalink)
References <1450487143595-16675.post@n7.nabble.com> <CAAJSdjj7y=3S-mLX8x3UGMv5vPq+va2yvxSFxmJLKKdp-fgfiw@mail.gmail.com> <1450639292355-16682.post@n7.nabble.com> <1450663923336-16683.post@n7.nabble.com> <CAAJSdji37iGJDic-yhuqiNtY0tHWm5sTqfineLJ+waxhS3tM-A@mail.gmail.com> <CAAJSdjgTbX9d-hGcgA_4-vaQDuUA-R1Frj-qBSTzXGFbFw0FOA@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1450708112 27760 208.118.235.17 (21 Dec 2015 14:28:32 GMT)
X-Complaints-To action@cs.stanford.edu
Cc Krem <valkrem@yahoo.com>, "bug-bash@gnu.org" <Bug-bash@gnu.org>
To John McKown <john.archie.mckown@gmail.com>
Envelope-to bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <CAAJSdjgTbX9d-hGcgA_4-vaQDuUA-R1Frj-qBSTzXGFbFw0FOA@mail.gmail.com>
User-Agent Mutt/1.4.2.3i
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From 139.137.100.1
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.14
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:12064

Show key headers only | View raw


On Mon, Dec 21, 2015 at 07:58:02AM -0600, John McKown wrote:
> OOPS, slight correction:
> 
> find . -maxdepth 2 -mindepth 2 -type f -name '*.csv' -o -name '*.txt'  |\
> egrep '^\./[0-9]' |\
>  while read i;do echo -e "${PWD
> ???##???*/
> } $(dirname ${i
> ???
> }
> ??? | cut -b 3-???
> ) $(basename ${i}) $(wc -l ${i})" ;done | cut -d " " -f 1,2,4,3

This is such an unreadable mish-mash of UTF-8 gibberish and misplaced
newlines that I can barely see the bugs.

But yeah, there are bugs here.  This entire approach fails horribly on
filenames that contain newlines, and you're failing to quote, so it'll
also fail on filenames that contain whitespace or glob characters.

${i} is NOT a valid replacement for "$i".  Ever.

You're also adding unnecessary backslashes (a | character already
causes the command to continue on the next line, so |\ is NEVER needed),
and you're using egrep with a BRE.  These aren't bugs, though; they're
just unnecessary.

Since I can't quite tell what your code's supposed to be doing, I'll
just give an outline of an approach that should get you started, based
on Krem's original request.

Note that mine is done in ASCII, so you can actually feed it to a shell.
And read it in any not-a-web-browser mail program.  Unlike whatever the
hell that UTF-8 gibberish was.

find ./[0-9]* -type f \( -iname '*.csv' -o  -iname '*.txt' \) ... \
  -exec bash -c '
    for f; do
      IFS=/ read -ra part <<< "$f"
      printf "%-10.10s  %-10.10s  %-20.20s  %5d\n" \
	"${part[1]}" "${part[2]}" "${part[3]}" "$(wc -l < "$f")"
      ...
    done
' _ {} +

You'll probably want to adjust the field widths.  And I left the ./[0-9]*
thing in, but I don't know why it's there.  It doesn't seem to be part of
Krem's problem statement.  If it causes problems, just use find . instead.

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: count Greg Wooledge <wooledg@eeg.ccf.org> - 2015-12-21 09:28 -0500

csiph-web