regex - Using command line, how do I get m out n possible results of each type? -


lets have shelves in store , each shelf has 0-9 boxes of specific kind. want select no more 4 boxes each shelf , till have 15 in total. how write command line code input file like

aa123 small aa124 small aa122 small bb345 medium .. .. 100s of such 

where first 2 letters define shelf , number tell box number on shelf.

for finding unique shelves, use

cat filename | awk '{print $1}' | cut -c 1-2 | sort | uniq | xargs 

then trying use input in for/while loop got stuck.

i think awk right tool this.

the following 1 liner prints first 4 occurrences of shelves, , 15 in total:

awk 'a[substr($1,1,2)]++ < 4 {if (t++>14) exit; print}' file 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -