distribution a écrit:
-------------------------------------------------------
> reretest
>
> i=1
>
> while [ $i -le $limite1 ]
> do
> tableau1 [ i ] =$(head -n$i $fichier1 | tail -n1)
> done
>
>
> i=1
>
> while [ $i -le $limite2 ]
> do
> tableau2 [ i ] =$(head -n$i $fichier2 | tail -n1)
> done
>
> ....
i=0
while read ligne; do
tableau [ $i ] = "$ligne"
((i++))
done <fichier
est la méthode correcte, mais j'avoue que je n'en vois pas bien l'intérêt. ceci dit, ça passe en moins de 10 secondes:
rg ~/test $ time for ((i=0; i<100000; i++)); do echo "champ "{1,2,3,4}" ligne $i;" "dernier champ ligne $i" >> fichier; done
real 0m10.800s
user 0m9.866s
sys 0m0.928s
rg ~/test $ i=0
rg ~/test $ time while read ligne; do tableau[ $i]="$ligne"; ((i++)); done <fichier
real 0m6.246s
user 0m6.052s
sys 0m0.190s
rg ~/test $ echo "${#tableau[ *]}"
100000
et il y a des trucs pour lesquels il n'y a pas photo
rg ~/test $ time sed -ne '85632 p' <fichier
champ 1 ligne 85631; champ 2 ligne 85631; champ 3 ligne 85631; champ 4 ligne 85631; dernier champ ligne 85631
real 0m1.072s
user 0m1.059s
sys 0m0.010s
rg ~/test $ time awk 'NR==85632' fichier
champ 1 ligne 85631; champ 2 ligne 85631; champ 3 ligne 85631; champ 4 ligne 85631; dernier champ ligne 85631
real 0m0.103s
user 0m0.085s
sys 0m0.018s
rg ~/test $ time head -n85631 fichier | tail -n1
champ 1 ligne 85630; champ 2 ligne 85630; champ 3 ligne 85630; champ 4 ligne 85630; dernier champ ligne 85630
real 0m0.083s
user 0m0.054s
sys 0m0.029s
Poste le Tuesday 26 May 2009 21:39:36