in reply to counting number of fileds
You can pipe into this or pass it a list of filenames that it should convert. It'll print it all to STDOUT.perl -ne "@_=split/,/;$a=@_>2?@_-3:0;print join',',@_[$a..$#_]"
I personally think that this is homework. I offer my solution anyway. :-)
The reason I think its homework is because its one of those simple questions thats easy to get wrong. All of the monks that offered code so far, (fwict) to their collective shame no doubt ;-), have actually not provided working code. And they seem to have some knowledge. No doubt a little more testing, a live sample of the data, whatever and they quickly would have noticed the oversight and fixed it correctly. But the fact remains. :-)
Anyway, don't think I was any better, I didn't notice the mistake until I did jdporters as a one liner and played with it for a few lines. I'm betting everybody who replied (and maybe a few more, since this'll be at the bottom of the list) are right about now smacking their foreheads and saying "less than three values" :-) (update the grep solution is only backwards...) Cause thats what I did.
Cheers.
PS: on *nix I think you spell it
but i'm not sure.perl -ne '@_=split/,/;$a=@_>2?@_-3:0;print join",",@_[$a..$#_]'
UPDATE If anybody wants to see the results of what has been posted so far read the source of this node.
--- demerphq
my friends call me, usually because I'm late....
|
|---|