Skip to content

Commit

Permalink
add new md
Browse files Browse the repository at this point in the history
  • Loading branch information
LYDongD committed Aug 14, 2019
1 parent 7675dab commit 65ab544
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dev-ops/shell/script/statistic.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,27 @@ done
rm $SYNC_FILE
```

### 单词分组统计排序

文本:

```
the day is sunny the the
the sunny is is
```

分组排序:

```
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r -k 1 | awk '{ print $2, $1 }'
```

* tr -s A B 将A替换成B, 这里将空格替换成回车
* sort 根据单词排序,这样把重复的单词排在了一起
* uniq -c 去重并计算重复的数量
* sort -r -k 1 按照第一列数量逆序排序
* awk '{print $2 $1}' 格式化打印第二列和第一列

0 comments on commit 65ab544

Please sign in to comment.