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

📄 col-totaler.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# Adds up a specified column (of numbers) in the target file.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#  Passing shell variables to the awk part of the script is a bit tricky.#  One method is to strong-quote the Bash-script variable#+ within the awk script.#     $'$BASH_SCRIPT_VAR'#      ^                ^#  This is done in the embedded awk script below.#  See the awk documentation for more details.# A multi-line awk script is invoked by:  awk ' ..... '# Begin awk script.# -----------------------------awk '{ total += $'"${column_number}"'}END {     print total}     ' "$filename"# -----------------------------# End awk script.#   It may not be safe to pass shell variables to an embedded awk script,#+  so Stephane Chazelas proposes the following alternative:#   ---------------------------------------#   awk -v column_number="$column_number" '#   { total += $column_number#   }#   END {#       print total#   }' "$filename"#   ---------------------------------------exit 0

⌨️ 快捷键说明

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