LInux - Show first X elements of an array

February 2017




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


Published by aakai1056. Latest update on July 18, 2011 at 12:41 PM by aakai1056.
This document, titled "LInux - Show first X elements of an array," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).