wf2.sh
来自「Shall高级编程」· Shell 代码 · 共 45 行
SH
45 行
#!/bin/bash# wf2.sh: Crude word frequency analysis on a text file.# Uses 'xargs' to decompose lines of text into single words.# Compare this example to the "wf.sh" script later on.# Check for input file on command line.ARGS=1E_BADARGS=65E_NOFILE=66if [ $# -ne "$ARGS" ]# Correct number of arguments passed to script?then echo "Usage: `basename $0` filename" exit $E_BADARGSfiif [ ! -f "$1" ] # Check if file exists.then echo "File \"$1\" does not exist." exit $E_NOFILEfi########################################################cat "$1" | xargs -n1 | \# List the file, one word per line. tr A-Z a-z | \# Shift characters to lowercase.sed -e 's/\.//g' -e 's/\,//g' -e 's/ /\/g' | \# Filter out periods and commas, and#+ change space between words to linefeed,sort | uniq -c | sort -nr# Finally prefix occurrence count and sort numerically.######################################################### This does the same job as the "wf.sh" example,#+ but a bit more ponderously, and it runs more slowly (why?).exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?