LInux - Show first X elements of an array

December 2016




Issue


I'm working on a small awk script and I some problems:
I have a table that I sort in a tab loop and I would like to view the first 10 elements.
for (i = 0; i <count; i + +) {print tab [i] | "sort"}
(I say that I am unable to use gawk to sort my array before with a sort)

Solution


You should make a head after the sort as follow;
lami20j@debian-acer:~$ cat fic|sort -g 
2 
3  
4 
10 
32 
110 
lami20j@debian-acer:~$ cat fic 
110 
2 
32 
4 
10 
3  
lami20j@debian-acer:~$ cat fic|sort -g 
2 
3  
4 
10 
32 
110 
lami20j@debian-acer:~$ cat fic|sort -g|head -2 
2 
3  

Note


Solved by lami20j

Related :

This document entitled « LInux - Show first X elements of an array » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.