Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i search a specific field in textfile?
    primarykey
    data
    text
    <p>i want to search field 5 of the text file, whether it is "Salaried", "Commission" or "Hourly" after searching it will store the data found in type. then will categorize into which type the Person is in and run the code accordingly to the type. I am stuck because i did not know how to use the search function and store it in a temporary field.</p> <p>code:</p> <pre><code> 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 &gt; 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}" &gt;&gt; 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 } </code></pre> <p>text file</p> <pre><code>3,Frak,IT,9765753,Salaried 1,May,CEO,9789292,Salaried 5,Samy,Sales user,92221312,Commission 2,Orange,cleaner,935233233,Hourly </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload