我需要一些帮助来编写一个脚本来比较运行awk和用户输入的值。
即:
cat employee.txt
100 Thomas Manager Sales $5,000
200 Jason Developer Technology $5,500
300 Sanjay Sysadmin Technology $7,000
400 Nisha Manager Marketing $9,500
500 Randy DBA Technology $6,000
EMPLOYERS=$(awk -F" " '{ print $2}' employee.txt)
echo "Enter the name of an employer: \c"
read employer
If/for/while employer is part of EMPLOYERS, echo a message.
提前致谢
答案 0 :(得分:2)
或只是
...
awk -v emp=$employer '$2==emp{print "found"}' employee.txt
-v
标志用于定义awk
变量,此处将shell值传递给脚本。
答案 1 :(得分:1)
我会更简单:
echo "Enter the name of an employer: \c"
read employer
if [[ $(awk -F" " '{ print $2}' employee.txt | grep $employer) = $employer ]]
then
echo Found
fi