From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21639 invoked by alias); 23 Aug 2011 01:38:27 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16279 Received: (qmail 10451 invoked from network); 23 Aug 2011 01:38:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at benizi.com does not designate permitted sender hosts) Date: Mon, 22 Aug 2011 21:37:45 -0400 (EDT) From: "Benjamin R. Haskell" To: TJ Luoma cc: Zsh Users Subject: Re: wc and leading spaces In-Reply-To: Message-ID: References: User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-1463810530-2042399641-1314063490=:10525" ---1463810530-2042399641-1314063490=:10525 Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT On Mon, 22 Aug 2011, TJ Luoma wrote: > Can anyone explain why 'wc' adds leading spaces to its output? ^1 > > for example: > > $ ls | wc -l | sed 's# #~#g' > ~~~~1299 > > or in another dir: > > $ ls | wc -l | sed 's# #~#g' > ~~~~~~47 > > I don't understand why: > > a) anyone would want leading spaces > > b) why they add enough spaces so that the numbers are "right" > justified (that might not be the proper term, but you get the idea) I don't get leading spaces² when any of '-c/--bytes', '-m/--chars', or '-l/--lines' is added. Without one of those options, the output of `wc` isn't useful for machine consumption without processing, so they made it "pretty" for human consumption. > Zsh question: Is there a way to get rid of the spaces without using > either "| awk '{print $1}'" or "| sed 's#^ *##g'"? var=${=$(ls | wc -l)} A possibly better way to count files: (pretty sure that was just an example... but either way...): set -- *(N) print $# A possibly better way to count lines (keeping with the ls example): ${#${(f):-"$(ls)"}} > ^1 — well, GNU's 'wc' does not seem to add leading spaces, but my > standard 'wc' in Mac OS X does… ²: with GNU `wc`... --version wc (GNU coreutils) 8.12 -- Best, Ben ---1463810530-2042399641-1314063490=:10525--