尝试从用户输入将变量传递给 awk:
已经尝试了 awk -v 的变体,但出现错误说明“awk:无效 -v 选项”,即使该选项已在 man 文件中列出。
#! /bin/bash
read -p "Enter ClassID:" CLASS
read -p "Enter FacultyName:" FACULTY
awk '/FacultyName/ {print}' data-new.csv > $FACULTY.csv
awk -vclass=${CLASS} '/class/ {print}' data-new.csv >> $FACULTY.csv
echo Class is $CLASS
echo Faculty member is $FACULTY