Tag Info

New answers tagged

0

It's fairly easy with awk. $ awk -F: '{count[$5]++}END{for(genre in count) print genre,count[genre]}' file Soul 1 Classic 9 Pop 2 Alternative 1 We split the line on : which appears to be the delimiter for your input lines. The genre appears as the 5th field of your line We will use genre as the key and increment every time we see it on your line In the ...


0

Assuming the header is not part of the file: awk -F: ' NR == 1 {max=$2; min=$2; next} length($2) > length(max) {max=$2} length($2) < length(min) {min=$2} END {print "longest=" max; print "shortest=" min} ' songs longest=Rockin' in the Free World shortest=1999


1

You don't see it in real time because, for purposes of efficiency, pipes are buffered. tail -f has to fill up the buffer, typically 4 kB, before the output is passed to awk. A fix is to use the unbuffer command which is part of the expect package: unbuffer tail -f logfile.log | awk -F" " '{print $1, $2, $7, $8}' This tricks tail into thinking it is ...


4

Indices to awk arrays can either be numeric (as in a traditional array) or strings (an associative array). So you can either do animal[1] = "cat" or animal["one"] = cat However, if you do animal[one] = cat awk will try to find a variable called 'one', fail, and effectively do this: animal[""] = cat So in your program, all three animals are ...



Top 50 recent answers are included