I'd like to add this command chain to alias to have a shorthand:
tail -10000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10 However, as alias it does not work as it should:
alias ttn="tail -10000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10" I tried to use single quote instead of double quote or use an escape character \ before awk's quotes but none worked. So appreciate your help.
awkanyway and not justcut -d' ' -f1? It depends what the first white space is in your input file - if every line starts with non-white-space followed by a blank char then you can just usecutinstead ofawk(which would be slower).$does not work but this one is fine:alias ttn='tail -10000 /var/log/nginx/access.log | awk '\''{print $1}'\'' | sort | uniq -c | sort -nr | head -10'. Please answer and I'll accept.ttn() { tail -10000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10"; }