Awk/Unix group by

$ awk -F, ‘NR>1{arr[$1]++}END{for (a in arr) print a, arr[a]}’ file.txt joe 1 jim 1 mike 3 bob 2 EXPLANATIONS -F, splits on , NR>1 treat lines after line 1 arr[$1]++ increment array arr (split with ,) with first column as key END{} block is executed at the end of processing the file for (a … Read more

How do you recursively unzip archives in a directory and its subdirectories from the Unix command-line?

If you want to extract the files to the respective folder you can try this find . -name “*.zip” | while read filename; do unzip -o -d “`dirname “$filename”`” “$filename”; done; A multi-processed version for systems that can handle high I/O: find . -name “*.zip” | xargs -P 5 -I fileName sh -c ‘unzip -o … Read more

Shell script “for” loop syntax

Brace expansion, {x..y} is performed before other expansions, so you cannot use that for variable length sequences. Instead, use the seq 2 $max method as user mob stated. So, for your example it would be: max=10 for i in `seq 2 $max` do echo “$i” done