而不是删除它重复的记录并创建类似的记录,我该如何解决这个问题:
Delete()
{
clear
f=0
echo "Enter Employee NO: \c"
read no
for j in `cat Employee.txt`
do
eno=$(echo "$j" | cut -d "," -f 1)
enm=$(echo "$j" | cut -d "," -f 2)
eadd=$(echo "$j" | cut -d "," -f 3)
eage=$(echo "$j" | cut -d "," -f 4)
egen=$(echo "$j" | cut -d "," -f 5)
edes=$(echo "$j" | cut -d "," -f 6)
ebal=$(echo "$j" | cut -d "," -f 7)
if [ $no -eq $eno ]
then
f=1
line=$(echo "$eno,$enm,$eadd,$eage,$egen,$edes,$ebal,false")
fnm=`cat Employee.txt`
d=$(echo "$fnm" | sed s/$j/$line/g )
echo $d > Employee.txt
echo " Delete Successfully "
fi
done
if [ f = 0 ]
then
echo " No Record Found "
fi
}
答案 0 :(得分:0)
您可以使用awk
单行
echo "Enter Employee NO: \c"
read no
awk -F ',' -v eno=$no '{if ($1 == eno ){$8 = "false" }OFS=",";print }' \
Attendance.txt >tmp_file && mv tmp_file Attendance.txt