Re: cut(1) and space delimiters
On Fri, Mar 19, 2010 at 09:34:47PM -0500, Ron Johnson wrote:
> Googled and followed examples, which work, but my specific problem
> doesn't work...
>
> WORKS:
> $ service="http mail ssh"
> $ echo $service | cut -d\ -f2
> mail
> $ echo $service | cut -d' ' -f2
> mail
> dpkg --get-selections | grep -v deinstall$ | awk '{print $1}'
>
>
> DOES NOT WORK:
> $ dpkg --get-selections | grep -v deinstall$ | cut -d' ' -f1
> $ dpkg --get-selections | grep -v deinstall$ | cut -d\ -f1
>
>
> Is the problem that there's so *much* whitespace in the dpkg listing?
Two things are biting you.
First, on my system,
'dpkg --get-selections | head -n1 | hd' shows tabs not spaces.
so use dpkg --get-selections | grep -v deinstall$ | cut -f1
The cut man page says tab is the default delimiter
Second, "cut -d' '" requires one space separating each field.
You could also use either of these:
dpkg --get-selections | grep -v deinstall$ | awk '{print $1;}'
dpkg --get-selections | grep -v deinstall$ | perl -nale' print $F[0];'
Mike
--
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Reply to: