[gull] SED, détecter un changement de contexte sur fichier CSV

Daniel Cordey dc at mjt.ch
Thu Oct 23 15:23:33 CEST 2008


On Thursday 23 October 2008, Frédéric Benninger wrote:

> Pour arriver à debut.csv
> 23.10.08 14:33:40;1;15
> 23.10.08 14:38:40;1;43
> fin.csv
> 23.10.08 14:35:40;1;12
> 23.10.08 14:39:40;1:47

Typiquement un probleme qui peut se resoudre avec 'awk', tout en restant 
lisible !!!

Mais je ne comprends pas tres bien la regle qui mene a la generation des 
lignes "fin.csv"... Peux-tu etre plus explicite pour cette partie ? Pour 
generer le "debut.csv", c'est quelque chose du style :

-- process.awk --

BEGIN {ctx = "0";}
{ if ($2 != ctx && $2 == "1")
    { 
        printf "%s;%s;%s\n", $1, $2, $3;
    }
  ctx = $2;
}

Executer avec :

awk -f  process.awk -F ';' <Data.csv

dc



More information about the gull mailing list