bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undocumented cut feature


From: Bob Proulx
Subject: Re: Undocumented cut feature
Date: Thu, 25 Oct 2007 14:59:13 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

Gambs, David (CONT) wrote:
> I am pulling data from the system and trying to extract three pieces out
> of that data. What I am finding is that when the field of interest is
> the last field, cut is adding a ^M to the end of the line:
> 
> vgdisplay > file1
> cat file1 | egrep -e Name -e "PE Size" -e Free > file2

Please web search for "useless use of cat".  Additionally in order to
get an appropriate exit code in the face of errors (such as full disk)
this is better done as:

  sed -n '/Name/p;/PE Size/p;/Free/p' file1 > file2

> cut -b23- file2 > file3

Hmm...  That is very fragile.  This would be better.

  awk '/VG Name/{print$3}/PE Size/{print$3}/Free/{print$5}' file1

But I can't imagine wanting all three at once.  I would normally
simply pick them off one at a time so that the values can be used.

  vgname=$(awk '/VG Name/{print$3}' file1)
  pesize=$(awk '/PE Size/{print$3}' file1)
  vgfree=$(awk '/Free/{print$5}' file1)

> cut -f1 -d' ' > file1

But what is the input file here?  file3?  And of course that is the
critical command that you are reporting problems about.

Can you reduce it further to a smaller standalone test case such as
this one?

  echo 2606 / 10.18 GB | cut -f1 -d' ' | od -tx1 -c

I am very suspicious that cut is introducing a CR in that flow.

> It is only at the last step that the ^M is added to the end of the
> volume group name extracted.

Are you sure?  That seems very unlikely to me.

> And from /etc/redhat-release:
> Red Hat Enterprise Linux AS release 3 (Taroon Update 6)
> And we are at core utilities: coreutils-4.5.3-28.4

I cannot recreate this problem on a RHEL3 machine.

> The information contained in this e-mail is confidential and/or proprietary
> ...

Oops!  I guess I should not have read your message.  Okay.  Here is a
counter disclaimer on my message.  Please forget that you have read my
reply.  Make no use of any information that you might have gleamed
from it.

More seriously though those disclaimers have no enforceability and are
found rude and annoying by many people on the network.  In the future
consider using a different email account such as any of the available
free email accounts available on the network that do not include such
annoying disclaimer messages.

  http://www.goldmark.org/jeff/stupid-disclaimers/

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]