Jump to content
unixbreak

Ajutor bash

Recommended Posts

Salut,

am niste fisiere csv pe care vreau sa le concatenez intr-unu singur fisier si sa le ordonez numeric. Problema e ca idul dupa care ordonez nu respecta o notatie standard. de ex .

sort -f *.csv > output.csv merge daca idul respecta forma id001 id002 id010 id100. Idurile pt fisierele mele sunt id1 id2 id10 id100 si asta imi strica sortarea.

sort -t, -V *.csv > output.csv merge perfect face exact ce imi trebuie pe masina de test care are sort --version gnu coreutils 8.5.0 nu 5.3.0 versiunea de la munca. Si bineinteles :) nu era implementata -V in 5.3.0

ma simt noob ... dar si ghinionist.

Daca va plictisiti si aveti o idee mai buna, bring it on !

Multumesc

Link to comment
Share on other sites

am facut un script perl pt asta ... in caz ca cineva are nevoie pe viitor ...

#!/usr/bin/perl

$infile = $ARGV[0];

if (!-e $infile){

$infile = "unsorted.csv";

};

open (IN, "<$infile"); @RAW){

$curline =~ s/\n//g;

@pieces = split(",", $curline);

$id = substr($pieces[1], 2);

$tmphash{$id} = $curline;

};

foreach $key (sort {$a <=> $b} keys %tmphash){

print $tmphash{$key} . "\n";

};

executati

perl script.pl unsorted.csv > sorted.csv

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...