我有这个 bash 脚本,它可以粘贴一个文本文件,我想让它变得更简单和更短以提高效率,有人对我如何做到这一点有任何想法吗?
$vi
function displayHelp
{
echo "Use '-f' to set the file to be used "
echo "Use '-s' to sort the data bya column"
echo "Use '-m' to output the rows which match this expression"
}
function displayColumn
{
columnnumber="$2"
awk '{print $'$columnnumber'}' $1
}
function displayParameter
{
parameter="$3"
columnnumber="$2"
awk -v s=$3 -v c=$2 '$c ~ s { print $0 }' $1
}
while getopts f:s:m:h opt
do
case "$opt" in
h) displayHelp;;
f) filepath="$OPTARG";;
s) column="$OPTARG"
displayColumn $filepath $column
;;
m) searchParam="$OPTARG"
displayParameter $filepath $column $searchParam
;;
esac
done