leetcode 的shell部分4道题整理
生活随笔
收集整理的這篇文章主要介紹了
leetcode 的shell部分4道题整理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對shell的某些細節還不是十分熟悉,借鑒了好多別人的東西
1. Word Frequency 此題很簡單,只要能排序就可以 cat words.txt |tr -s " " "\n" sort | unique -c | sort -r | awk '{print $2" "$1}' 2.?Valid Phone Numbers
? cat file.txt | awk '/^\d{3}-\d{3}-\d{4}$/| /^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$/' ? 3.Transpose File
?cat file.txt| awk '{? ? max_nf = NF ? ? max_nr = NR ? ? for(x=1;x<=max_nf;x++){ ? ? ? ? vector[x,NR]=$x; ? ? } } END{ ? ? for(x = 1;x <= max_nf;x++){ ? ? ? ? for( y = 1;y <= max_nr ; y++){ ? ? ? ? ? ? printf("%s",vector[x,y]) ? ? ? ? ? ? if (y < max_nr) ? ? ? ? ? ? ? ? ? printf(" ") ? ? ? ? } ? ? if (x < max_nf) ? ? ? ? ? printf("\n") } } ' ? 4.
Tenth Line
?cat file.txt|awk 'NR==10'轉載于:https://www.cnblogs.com/chengxuyuanxiaowang/p/4734280.html
總結
以上是生活随笔為你收集整理的leetcode 的shell部分4道题整理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python2.7虚拟环境virtual
- 下一篇: iOS 9之WatchKit for W