0

All of these are being written in case :

Case 1:

 echo "${name}:${identity}:${hp}:$now:"0"" >> info.txt      # write to info.txt

so i will have something like this : Tom:8:987654:commission:0 # i assign it to 0 first

Case 2 :

echo -n "Enter employee's name:"
read name

S=`grep $name info.txt`;    

    if test -z $S 
then
echo "No details with employee name  $name"
else
echo "$S" | cut -d: -f4 // display 4th column.
echo 
echo -n "Enter hourly wage: "; read wage;
echo -n "Enter hours worked this week: "; read hours;

pay=$hours-40*$wage;          

echo -n "To update next payroll : press Y else N to go main menu: "     

read option
case "$option" in 
[Yy]*)  echo "Payroll have been updated."
    echo grep $name | sed -i s/\:*$/$pay/n info.txt //error         
    ;;
[Nn]*) 
    echo "Press Enter to view the Main"     
esac
fi

My textfile looks like this:

Tom:8:987654:commission:0
Tommy:7:12379813:hourly:0
Fan:5:2132131:salaried:0

I am trying to replace the last column value to $pay ( not all columns only the specific name by the user ) Lets say the $pay is 10 and $name is Tommy

This is the expected textfile:

   Tom:8:987654:commission:0
    Tommy:7:12379813:hourly:10
    Fan:5:2132131:salaried:0

But i got this error : sed: -e expression #1, char 15: unknown option tos'`

i am doing in on ubuntu terminal .

1

Replace the whole line:

sed -e "/$name/s/[0-9]*$/$pay/" -i info.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.