Input:
иностранный язык 311
родной язык 226
настоящий друг 215
лаконичный ответ 204
милый друг 197
лучший друг 193
громкий голос 183
трава зеленая 171
упрямый осел 169
снег белый 158
передать привет 158
история учебник 13
история страны 13
история партии 13
истинный патриот 13
истинный друг 13
иностранный агент 13
output:
иностранный язык 311 0.959877
родной язык 226 1
настоящий друг 215 1
лаконичный ответ 204 1
милый друг 197 1
лучший друг 193 1
громкий голос 183 1
трава зеленая 171 1
упрямый осел 169 1
снег белый 158 1
передать привет 158 1
история учебник 13 0.333333
история страны 13 0.333333
история партии 13 0.333333
истинный патриот 13 0.5
истинный друг 13 0.5
иностранный агент 13 0.0401235
awk: awk -F' ' 'NR==FNR{a[$1]+=$3;next}{print($0,$3/a[$1])}' test test
Showing posts with label awk. Show all posts
Showing posts with label awk. Show all posts
Tuesday, February 7, 2012
Wednesday, February 1, 2012
awk filtering and soring by parameter
file:
aaa \t bbb \t 3
bbb \t ssd \t 4
Exclude rows with $3 (3rd parameter) <=1 and sort it by 3rd column:
awk -F"\t" '$3>1 {print}' test | sort -n -r -t' ' -k3> test_filter_gt1
Get number of different words in the 2nd column:
awk -F" " '{print $2}' test_filter_gt1 | sort | uniq -c -i | wc -l
aaa \t bbb \t 3
bbb \t ssd \t 4
Exclude rows with $3 (3rd parameter) <=1 and sort it by 3rd column:
awk -F"\t" '$3>1 {print}' test | sort -n -r -t' ' -k3> test_filter_gt1
Get number of different words in the 2nd column:
awk -F" " '{print $2}' test_filter_gt1 | sort | uniq -c -i | wc -l
Sunday, January 15, 2012
awk , add column to file
Add column with line number to file:
awk '{print NR"\t"$0}' degrees_dir > degrees_dir_order
After:
head degrees_dir_order
1 669
2 667
3 600
4 596
5 580
6 549
7 490
8 460
9 454
10 447
awk '{print NR"\t"$0}' degrees_dir > degrees_dir_order
After:
head degrees_dir_order
1 669
2 667
3 600
4 596
5 580
6 549
7 490
8 460
9 454
10 447
Subscribe to:
Posts (Atom)
