Skip to content

Instantly share code, notes, and snippets.

@livc
Last active February 3, 2017 13:30
Show Gist options
  • Save livc/bb4d770bc044faecabe3cea759ee9059 to your computer and use it in GitHub Desktop.
Save livc/bb4d770bc044faecabe3cea759ee9059 to your computer and use it in GitHub Desktop.
`awk` common usage
// vim: syntax=bash
awk -F"\t" '{if(NR==FNR){dict[$4]=1}else{if(!($1 in dict)){print}}}' reskey_cuid.mup ./20161122 > 2333333
awk substr(s, a, b)
awk '{print substr($0,2,6)}' file
cat ../../../navi_id_dict |awk -F "\t" 'dict[$1]=$2''{print $1}'
cat 20161019 |awk -F":" '{dict[$1]+=$2}END{for (x in dict){printf("%s,%d,%.2f%s\n", x, dict[x], 100*dict[x]/dict["Tag 1"], "%")}}' | sort -t "," -k2nr > 20161019sum
cat 20161012 |awk -F" " '{dict[$1]+=$2}END{for(x in dict){printf("%s,%d,%.2f%s\n", x,dict[x],100*dict[x]/dict["guanzhu"], "%")}}' |sort -t"," -k2nr > 20161012.csv
head recommend_cover_20160930 |awk '{a+=$1; b+=$2; c+=$3} END {printf("%d %d %d\n", a, b, c)}'
cat ans |awk -F"," '{printf("%s,%d,%d,%d,%.5f\n",$1,$2,$3,a,$3/a)}' a=60201167
cat 20161019 |awk -F":" '{dict[$1]+=$2}END{for(x in dict){print x"\t"dict[x]}}' |sort -k3nr n:以数值来排序 r:降序 -t ","指定分割符 -k指定列数
cat 20161106 |awk -F'\t' '{if($1=="百度百科"){print}}'
#shuffle 代码
awk '{if(num<count){line[num]=$0;num++;}else{n=int(rand()*num);if(n<count){line[n]=$0;};num++}}END{for(i in line){print line[i]}}' count=$COUNT $INPUT_PATH |sed 1d > data/random_rank_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment