1
A
回答
1
awk ' { # call awk
# file -> is array
# $0 -> current row/line/record
# here $0 is used array index/key
# ++ is post increment meaning
# if line was found before it will increment by 1
# so file[$0]++ holds count of occurrence of line
# suppose you got 4 lines, in that 3 are duplicates, then
# for such index file[<such_line>] will be 3
file[$0]++
}
# end block as name suggests executes at the end
END {
# loop through array file
# j as index
for (j in file) {
# print array key, and array value
print j,file[j]
}
}
' file
例子:
$ cat infile
lineA
lineB
lineA
lineB
lineA
lineC
$ awk ' {file[$0]++} END { for (j in file)print j,"repeated",file[j],"times in file :",FILENAME }' infile
lineA repeated 3 times in file : infile
lineB repeated 2 times in file : infile
lineC repeated 1 times in file : infile
0
以下可能會幫助你一樣。
awk ' {
file[$0]++ ##creating an array named file and with respect to current line as index, incrementing its count each time with one if same entry comes in array file.
}
END { ##Starts END section of awk code here.
for (j in file) { ##starting for loop which will traverse through array file.
print j,file[j] ##Printing value of j(which will be index of array named file(or other words current line value)) and printing the value of array file with index of j.
} } '
+0
非常感謝你,你幫了我很多! – Mike
+1
@Mike,很高興它幫助你,看到這個https://stackoverflow.com/help/someone-answers – RavinderSingh13
相關問題
- 1. 一步一步運行shell命令
- 2. Rspec中的命令步驟和說明步驟
- 3. 需要一步一步的說明添加VideoJs VAST插件
- 4. 需要關於同步和異步操作的一些說明
- 5. 一步一步模擬Matlab命令行模擬Simulink模型
- 6. Apache Nutch步驟說明
- 7. c呼叫同步是否與命令同步一樣?
- 8. GDB步過命令
- 9. 跑步系列在一個命令行命令,在cmd
- 10. 對於awk中的特定命令的說明
- 11. 希望對異步JavaScript代碼和同步代碼進行一些說明
- 12. Lucene.Net一步一步
- 13. Android誰能告訴我如何從命令行一步一步創建apk?
- 14. sftp獲取命令說明
- 15. 命令模式說明
- 16. 有人可以請給我一步一步的說明如何獲得一個Java小程序正確簽署
- 17. Rails 3註冊步驟一步一步
- 18. 一步一步在Windows 7
- 19. matplotlib,一步一步動畫
- 20. Ajax請求一步一步
- 21. Iex pry一步一步來?
- 22. 一步一步Google SSO(java)?
- 23. Java Web Start。一步一步
- 24. coq一步一步簡化?
- 25. 一步一步gflot教程?
- 26. Autohotkey,一步一步執行
- 27. Unity3D一步一步移動
- 28. 一步一步的火法
- 29. Selenium一步一步學習
- 30. 驗證一步一步
非常感謝你,你也幫助了我這麼多! – Mike