我有一个文本文件(particulars.txt),其中包含
personId,personName,employmentType
详情.txt
1,jane,partTime
2,bob,fullTime
3,john,fullTime
如何做到这一点,如果我输入工人的姓名,它将检查该人是全职还是兼职工人,并提示用户输入薪水并仅为该人重写回文件. 我将更详细地解释。
例如
Enter Name:jane
jane is a partTime staff
Enter Hourly Salary:10
所以文本文件(particulars.txt)现在将是
1,jane,partTime,10
2,bob,fullTime
3,johnfullTime
示例二
Enter Name:bob
bob is a fullTime staff
Enter monthly Salary:1600
所以文本文件(particulars.txt)现在将是
1,jane,partTime,10
2,bob,fullTime,1600
3,john,fullTime
这就是我的代码
#!/bin/bash
fileName="particulars.txt"
read -p "Enter name:" name
if grep -q $name $fileName; then
employmentType=$(grep $name $fileName | cut -d, -f4)
echo "$name is $employmentType" staff"
if [ $employmentType == "partTime" ]; then
echo "Enter hourly pay:"
read hourlyPay
#calculations for monthly salary(which I have not done)
elif [ $employmentType == "fullTime" ]; then
echo "Enter monthly salary:"
read monthlySalary
fi
else
echo "No record found"
fi
read -p "Press[Enter Key] to Contiune.." readEnterKey
我只能找到该人属于哪种工作类型,但我不确定我应该如何/应该怎么做才能在该特定人的行尾添加薪水。我已经阅读了 sed ,但我仍然对如何使用 sed 来实现我的结果感到困惑,从而寻求你们的帮助。提前致谢