⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wf2.sh

📁 Shall高级编程
💻 SH
字号:
#!/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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -