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


Groups > alt.comp.lang.shell.unix.bourne-bash > #235 > unrolled thread

tr squeeze repeats does not remove multiple spaces coming from a piped du command

Started by"Zangune" <Zangune@Example.Com>
First post2018-10-03 17:05 +0200
Last post2018-10-03 22:48 -0600
Articles 6 — 3 participants

Back to article view | Back to alt.comp.lang.shell.unix.bourne-bash


Contents

  tr squeeze repeats does not remove multiple spaces coming from a piped du command "Zangune" <Zangune@Example.Com> - 2018-10-03 17:05 +0200
    Re: tr squeeze repeats does not remove multiple spaces coming from a piped du command "Michael F. Stemper" <michael.stemper@gmail.com> - 2018-10-03 12:47 -0500
      Re: tr squeeze repeats does not remove multiple spaces coming from a piped du command "Zangune" <Zangune@Example.Com> - 2018-10-04 01:44 +0200
    Re: tr squeeze repeats does not remove multiple spaces coming from a piped du command Grant Taylor <gtaylor@tnetconsulting.net> - 2018-10-03 11:49 -0600
      Re: tr squeeze repeats does not remove multiple spaces coming from a piped du command "Zangune" <Zangune@Example.Com> - 2018-10-04 01:54 +0200
        Re: tr squeeze repeats does not remove multiple spaces coming from a piped du command Grant Taylor <gtaylor@tnetconsulting.net> - 2018-10-03 22:48 -0600

#235 — tr squeeze repeats does not remove multiple spaces coming from a piped du command

From"Zangune" <Zangune@Example.Com>
Date2018-10-03 17:05 +0200
Subjecttr squeeze repeats does not remove multiple spaces coming from a piped du command
Message-ID<pp2ltd$1908$1@gioia.aioe.org>
Greetings, I want to know the total size of a directory content, so I 
use this command:

du -c /path | tr -s ' '

but I got this (this is just the last line):

510    total

please note that there are 4 spaces between "0" and "t".
I would expect the result to be:

510 total

please note that there is just one space between "0" and "t".
As far as I can see, the "du" command result is alined in columns with 
spaces, but the "tr" command does not remove those repeated spaces like 
it does in

echo 'a       b' | tr -s ' '

Why doesn't a "tr" command with the "squeeze repeats" option remove 
repeated spaces of a piped "du" command result?
Please note that I found a workaround, this one:

echo $(du -c /path)

but I am more interested in the theoretical problem solution (and 
logic), rather than the practical one.
Regards. 

[toc] | [next] | [standalone]


#236

From"Michael F. Stemper" <michael.stemper@gmail.com>
Date2018-10-03 12:47 -0500
Message-ID<pp2vbl$a30$1@dont-email.me>
In reply to#235
On 2018-10-03 10:05, Zangune wrote:
> Greetings, I want to know the total size of a directory content, so I
> use this command:
> 
> du -c /path | tr -s ' '
> 
> but I got this (this is just the last line):
> 
> 510    total
> 
> please note that there are 4 spaces between "0" and "t".

Are you quite sure? I just tried the same thing, and didn't find any
spaces between the number and the word "total". What I did find was
a tab:

username@hostname$ du -c dtd
84	dtd
84	total
username@hostname$ du -c dtd | sed 's/ /s/g'
84	dtd
84	total
username@hostname$ du -c dtd | sed 's/\t/tab/g'
84tabdtd
84tabtotal
username@hostname$

> I would expect the result to be:
> 
> 510 total
> 
> please note that there is just one space between "0" and "t".
> As far as I can see, the "du" command result is alined in columns with
> spaces,

Nope, tabs are much better for column alignment than are spaces. They
yield, one might say, a "tabular" format.

-- 
Michael F. Stemper
Psalm 94:3-6

[toc] | [prev] | [next] | [standalone]


#238

From"Zangune" <Zangune@Example.Com>
Date2018-10-04 01:44 +0200
Message-ID<pp3kl0$u0d$1@gioia.aioe.org>
In reply to#236
"Michael F. Stemper" wrote

> du -c dtd | sed 's/\t/tab/g'
> 84tabdtd
> 84tabtotal

Thanks, I can confirm that a sed substitution shows me that there is a 
single "tab" between the last number and the "total" word.
Indeed, if I leftclick on a terminal just after the last number and I 
highlight what I can find between the numbers and the "total" word, the 
highlight "trace" shows me four spaces; more than this, the highlighted 
characters are automatically copied and, when pasted, they appear as 
four spaces. That fooled me, but I guess this behaviour of the program I 
use for terminal emulation is intentional, I have to investigate about 
that.
Regards. 

[toc] | [prev] | [next] | [standalone]


#237

FromGrant Taylor <gtaylor@tnetconsulting.net>
Date2018-10-03 11:49 -0600
Message-ID<pp2vu8$cvf$1@tncsrv09.home.tnetconsulting.net>
In reply to#235
On 10/03/2018 09:05 AM, Zangune wrote:
> Why doesn't a "tr" command with the "squeeze repeats" option remove 
> repeated spaces of a piped "du" command result?

My first guess is that you're telling du to look for a space, which 
doesn't include tabs like I see in my du's output.

I tend to prefer awk when I'm wanting to do things in a white space 
length agnostic way.



-- 
Grant. . . .
unix || die

[toc] | [prev] | [next] | [standalone]


#239

From"Zangune" <Zangune@Example.Com>
Date2018-10-04 01:54 +0200
Message-ID<pp3kst$u8m$1@gioia.aioe.org>
In reply to#237
"Grant Taylor" wrote:

> you're telling du to look for a space, which doesn't include tabs like 
> I see in my du's output

Thank you for the "tab" hint.
I believe you meant "tr" instead of "du" in this sentence, before the 
comma.
It is a single "tab", but, as I wrote to "Michael F. Stemper" under his 
first reply, I get fooled by my terminal emulator behaviour, my bad 
anyway.
Regards. 

[toc] | [prev] | [next] | [standalone]


#240

FromGrant Taylor <gtaylor@tnetconsulting.net>
Date2018-10-03 22:48 -0600
Message-ID<pp46ho$7ls$1@tncsrv09.home.tnetconsulting.net>
In reply to#239
On 10/03/2018 05:54 PM, Zangune wrote:
> Thank you for the "tab" hint.

You're welcome.

> I believe you meant "tr" instead of "du" in this sentence, before the 
> comma.

Oops.  Thank you for helping me help you.  ():-)

> It is a single "tab", but, as I wrote to "Michael F. Stemper" under his 
> first reply, I get fooled by my terminal emulator behaviour, my bad anyway.
> Regards.

Ya.  I've run into things like that before.  I will occasionally use od, 
xxd, or vim - to look at what comes from STDOUT.



-- 
Grant. . . .
unix || die

[toc] | [prev] | [standalone]


Back to top | Article view | alt.comp.lang.shell.unix.bourne-bash


csiph-web