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

📄 col-totaler3.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash#  Yet another version of the "column totaler" script (col-totaler.sh)#+ that adds up a specified column (of numbers) in the target file.#  This uses the environment to pass a script variable to 'awk' . . .#+ and places the awk script in a variable.ARGS=2E_WRONGARGS=65if [ $# -ne "$ARGS" ] # Check for proper no. of command line args.then   echo "Usage: `basename $0` filename column-number"   exit $E_WRONGARGSfifilename=$1column_number=$2#===== Same as original script, up to this point =====#export column_number# Export column number to environment, so it's available for retrieval.# -----------------------------------------------awkscript='{ total += $ENVIRON["column_number"] }END { print total }'# Yes, a variable can hold an awk script.# -----------------------------------------------# Now, run the awk script.awk "$awkscript" "$filename"# Thanks, Stephane Chazelas.exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -