0

テキストファイルのフィールド5を検索したいのですが、「給与」、「コミッション」、「時給」のいずれであっても、検索した後、タイプで見つかったデータが保存されます。次に、Person がどのタイプに属しているかを分類し、タイプに応じてコードを実行します。検索機能を使って一時フィールドに保存する方法がわからなかったので行き詰まっています。

コード:

        payroll()
        {
          line=`grep -i "^${update_empID}," $data`
          empID=`echo $line | cut -d "," -f1`
          name=`echo $line | cut -d "," -f2`
          job=`echo $line | cut -d "," -f3`
          phone=`echo $line | cut -d "," -f4` 
          type=`echo $line | cut -d "," -f5`

           clear
           echo -e "Enter the pay"
           echo -en "Enter ID: "
           read empid_search

           #Check if particular entry to search for existed to perform deletion
           if [ `count_lines "^${empid_search},"` -eq 0 ]
           then
               echo "Error: This particular record does not exist!!"
           else
               echo "Please verify update of this employee's record: " #Prompt for confirmation of employee details
            echo
               echo "Employee's Details: "
               locate_lines "^${empid_search},"   #Find location of the entry     
               awk -F ',' '$5 == "Salaried Employee"' $PAYROLL > types

           if [$type="Salaried"]
           then
            echo "$name is a Salaried"
            echo "Enter Salary :"
            read salary

          if [$type="Hourly"]
           then
            echo "$name is a Hourly"
            echo "Enter employee's Hourly Wage :"
                        read hourly_wage
                        echo "Enter hours worked this week :"
                        read hours_worked



             echo "${empID},${name},${job},${phone},${Type},${salary}" >> tmpfile ; mv tmpfile $data
               echo " particulars has been updated!!"
               fi      
            else
            echo "f"     
           fi

        }

count_lines()
{
   grep -i "$@" $PAYROLL | wc -l            
}
#Function to locate lines that match $1
locate_lines()
{
  result=-1
  if [ ! -z "$1" ]
  then
     grep -i "$@" $PAYROLL    
     result=$?  #Returns 0 if previous command is successful
  fi
  return $result   
}

テキストファイル

3,Frak,IT,9765753,Salaried
1,May,CEO,9789292,Salaried
5,Samy,Sales user,92221312,Commission
2,Orange,cleaner,935233233,Hourly
4

1 に答える 1