Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Philippe Naudin
Le mer. 29 août 2012 01:44:48 CEST, Rajagopal Swaminathan a écrit:

 Greetings,
 
 On Wed, Aug 29, 2012 at 1:36 AM,  m.r...@5-cent.us wrote:
 
  I've never been that good with cut. I'm going to see the author, Dave
  Ihnat this weekend, who sometimes shows up here... but in the meantime,
  you might use
  awk 'BEGIN {FS=,;}{print $2 , $3 , $1;}' infile
 
 
 I tried it on an xp box with GnuWin32 binaries. It barked some error
 showing the single quote.
 
 I will try on a centos box later (grinwhich I am silently injecting
 [installing] into that env after handwaving the xp/grin).

You can also try with bash :
while IFS=, read A B C ; do echo $B,$C,$A ; done  infile

Regards,

-- 
Philippe Naudin
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Rajagopal Swaminathan
On Wed, Aug 29, 2012 at 2:15 AM, Markus Falb markus.f...@fasel.at wrote:
 On 28.8.2012 21:59, Rajagopal Swaminathan wrote:

 cut cuts out, that what it does.
 I think it works exactly as advertised.
 On my system the manpage says

 ...snip
 Selected input is written in the same order that it is
read, and is written exactly once
 snap...


See below

 Is it specific to linux?

 No!

I would think, yes.

From: 
http://www.unix.com/unix-dummies-questions-answers/117504-question-cut-command.html

[quote]
 08-22-2009
Scott's Avatar  
Scott Scott is offline Forum Staff
Administrator

Join Date: Jun 2009
Location: Switzerland - ZH
Posts: 5,632
Thanks: 136
Thanked 596 Times in 515 Posts

In AIX (for example) if you said

Code:
echo 1,2,3,4,5 | cut -d, -f3,1,5

you would get output as 3,1,5

But the cut command in Linux behaves differently.

From the man page:
Quote:
Selected input is written in the same order that it is read, and is
written exactly once.

Which I think is poor. I can't see any way to do what you want with cut.

[unquote]

Thanks for everybody who pitched in

Any the issue got transformed into something else altogether (PHB,
vlookup 'experts' and the such for time being)

-- 

Regards,

Rajagopal
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Les Mikesell
On Wed, Aug 29, 2012 at 10:43 AM, Rajagopal Swaminathan
raju.rajs...@gmail.com wrote:

 But the cut command in Linux behaves differently.

 From the man page:
 Quote:
 Selected input is written in the same order that it is read, and is
 written exactly once.

 Which I think is poor. I can't see any way to do what you want with cut.

 [unquote]

If you are willing to use tmp files you can:
cut -d, -f1 input tmp1
cut -d, -f2 input tmp2
cut -d, -f3 input tmp3

paste -d, tmp1 tmp3 tmp2 file_I_wanted
rm tmp1 tmp2 tmp3

There's probably a clever way to do this with tee and fifos to handle
unlimited stream sizes but I'm too lazy to work it out.

-- 
   Les Mikesell
 lesmikes...@gmail.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Markus Falb
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 29.8.2012 17:43, Rajagopal Swaminathan wrote:
 On Wed, Aug 29, 2012 at 2:15 AM, Markus Falb
 markus.f...@fasel.at wrote:
 On 28.8.2012 21:59, Rajagopal Swaminathan wrote:
 
 cut cuts out, that what it does. I think it works exactly as
 advertised. On my system the manpage says
 
 ...snip Selected input is written in the same order that it is 
 read, and is written exactly once snap...
 
 
 See below
 
 Is it specific to linux?
 
 No!
 
 I would think, yes.

On a OS-X, and thats non arguably not linux-ish (means gnu-ish) but
bsd-ish

$ echo 1,2,3,4,5 | cut -d, -f3,1,5
1,3,5

So it's definitely not specific to linux.

 
 From:
 http://www.unix.com/unix-dummies-questions-answers/117504-question-cut-command.html

  [quote] ... In AIX (for example) if you said
 
 Code: echo 1,2,3,4,5 | cut -d, -f3,1,5
 
 you would get output as 3,1,5

I tend to think that AIX is not posix compliant, then.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html

The behaviour of cut makes sense to me, actually. I remember one of
the UNIX paradigms and thats do only one thing but do it good

However, I realize that I do not suggest a better way to do what you
want to do, but I do not think I have to, there were so many hints in
this thread pointing you to awk and I remember actually one shell only
example.
- -- 
Kind Regards, Markus Falb
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA+SLIACgkQYoWFBIJE9eUJTwCfY7LL6BaE5gFJbBIeHoRrRpus
R0UAn3m7wjXIelJy36jYLbNexoue4NN4
=uVtC
-END PGP SIGNATURE-

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Les Mikesell
On Wed, Aug 29, 2012 at 11:52 AM, Markus Falb markus.f...@fasel.at wrote:

 From:
 http://www.unix.com/unix-dummies-questions-answers/117504-question-cut-command.html

  [quote] ... In AIX (for example) if you said

 Code: echo 1,2,3,4,5 | cut -d, -f3,1,5

 you would get output as 3,1,5

 I tend to think that AIX is not posix compliant, then.
 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html

 The behaviour of cut makes sense to me, actually. I remember one of
 the UNIX paradigms and thats do only one thing but do it good

So sed with a regexp?
 sed  -e 's/\([^,]*\),\([^,]*\),\([^,]*\)/\1\3\2/'

-- 
   Les Mikesell
 lesmikes...@gmail.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Gordon Messmer
On 08/29/2012 09:52 AM, Markus Falb wrote:
 From:
 http://www.unix.com/unix-dummies-questions-answers/117504-question-cut-command.html
   [quote] ... In AIX (for example) if you said
 Code: echo 1,2,3,4,5 | cut -d, -f3,1,5
 you would get output as 3,1,5
 I tend to think that AIX is not posix compliant, then.
 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html

Well, according to that document, AIX's cut seems to behave as POSIX and 
Scott (on unix.com) is simply wrong about the application's behavior.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-29 Thread Stephen Harris
On Wed, Aug 29, 2012 at 12:25:29PM -0700, Gordon Messmer wrote:
 On 08/29/2012 09:52 AM, Markus Falb wrote:
  From:
  http://www.unix.com/unix-dummies-questions-answers/117504-question-cut-command.html
[quote] ... In AIX (for example) if you said
  Code: echo 1,2,3,4,5 | cut -d, -f3,1,5
  you would get output as 3,1,5
  I tend to think that AIX is not posix compliant, then.
  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html
 
 Well, according to that document, AIX's cut seems to behave as POSIX and 
 Scott (on unix.com) is simply wrong about the application's behavior.

No need to guess about what AIX does:
  $ uname -svr
  AIX 1 6
  $ oslevel
  6.1.0.0
  $ echo 1,2,3,4,5 | cut -d, -f3,1,5
  1,3,5
  $

-- 

rgds
Stephen
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] Cut command behaviour - bug or feature

2012-08-28 Thread Rajagopal Swaminathan
Greetings,

I have a CSV file with three fields.
eg.

a1,b1,c1
a2,b2,c2


I wanted the output to be:
b1,c1,a1
b2,c2,a2


the command
cut -d, -f2,3,1 file

returns

a1,b1,c1

cut -d, -f2,3 file

works as advertised.

Is it specific to linux?

In that case how do I go about swapping two columns? I do not think a
gazzillion byte gui is required.

The file size is about 43Megs.

any ideas?

-- 
Regards,

Rajagopal
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-28 Thread m . roth
Rajagopal Swaminathan wrote:
 Greetings,

 I have a CSV file with three fields.
 eg.

 a1,b1,c1
 a2,b2,c2
 

 I wanted the output to be:
 b1,c1,a1
 b2,c2,a2
 

 the command
 cut -d, -f2,3,1 file

 returns

 a1,b1,c1

 cut -d, -f2,3 file

 works as advertised.

 Is it specific to linux?

 In that case how do I go about swapping two columns? I do not think a
 gazzillion byte gui is required.

 The file size is about 43Megs.

I've never been that good with cut. I'm going to see the author, Dave
Ihnat this weekend, who sometimes shows up here... but in the meantime,
you might use
awk 'BEGIN {FS=,;}{print $2 , $3 , $1;}' infile

   mark

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-28 Thread Rajagopal Swaminathan
Greetings,

On Wed, Aug 29, 2012 at 1:36 AM,  m.r...@5-cent.us wrote:

 I've never been that good with cut. I'm going to see the author, Dave
 Ihnat this weekend, who sometimes shows up here... but in the meantime,
 you might use
 awk 'BEGIN {FS=,;}{print $2 , $3 , $1;}' infile


I tried it on an xp box with GnuWin32 binaries. It barked some error
showing the single quote.

I will try on a centos box later (grinwhich I am silently injecting
[installing] into that env after handwaving the xp/grin).

-- 
Regards,

Rajagopal
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-28 Thread Markus Falb
On 28.8.2012 21:59, Rajagopal Swaminathan wrote:
 Greetings,
 
 I have a CSV file with three fields.
 eg.
 
 a1,b1,c1
 a2,b2,c2
 
 
 I wanted the output to be:
 b1,c1,a1
 b2,c2,a2
 
 
 the command
 cut -d, -f2,3,1 file
 
 returns
 
 a1,b1,c1

cut cuts out, that what it does.
I think it works exactly as advertised.
On my system the manpage says

...snip
Selected input is written in the same order that it is
   read, and is written exactly once
snap...

 Is it specific to linux?

No!
-- 
Kind Regards, Markus Falb



signature.asc
Description: OpenPGP digital signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-28 Thread Les Mikesell
On Tue, Aug 28, 2012 at 2:59 PM, Rajagopal Swaminathan
raju.rajs...@gmail.com wrote:

 I have a CSV file with three fields.
 eg.

 a1,b1,c1
 a2,b2,c2
 

 I wanted the output to be:
 b1,c1,a1
 b2,c2,a2
 

 the command
 cut -d, -f2,3,1 file

 returns

 a1,b1,c1

 cut -d, -f2,3 file

 works as advertised.

 Is it specific to linux?

 In that case how do I go about swapping two columns? I do not think a
 gazzillion byte gui is required.

 The file size is about 43Megs.

 any ideas?

If you are sure that the fields will never contain commas, there are
any number of ways to split lines into variables in any number of
scripting languages including bash.   However, if the input is
'generic csv' that is allowed to have quotes around fields with
embedded commas it can be hard to parse.   I'd recommend perl with the
Text::CSV module so you don't have to deal with parsing yourself.

-- 
  Les Mikesell
lesmikes...@gmail.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Cut command behaviour - bug or feature

2012-08-28 Thread Stephen Harris
On Wed, Aug 29, 2012 at 01:29:05AM +0530, Rajagopal Swaminathan wrote:
 a1,b1,c1
 a2,b2,c2

 cut -d, -f2,3,1 file

Will not work.  The -f flag specifies what columns; not the order.
Everyone makes that mistake once :-)

 In that case how do I go about swapping two columns? I do not think a
 gazzillion byte gui is required.

Use awk
  awk -F, '{print $2 , $3 , $1}'

-- 

rgds
Stephen
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos