LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   storing data into text file (https://www.linuxquestions.org/questions/linux-newbie-8/storing-data-into-text-file-4175483664/)

zkyzky 11-06-2013 07:20 PM

storing data into text file
 
Hi, i would like to store my gross wage into my text file in the fifth segment like ${Name},${ID},${HP},${Type}, ${wage}
what codes should i add for me to execute that.
Code:

line=`grep -i "$Name" $PAYROLL`
  Type=`echo $line | cut -d "," -f4`

if [[ $Type -eq $one ]];
then
echo "He is an Salaried employee"
echo "Enter hourly wage: "
read wage
echo "Enter hours worked this week: "
read hours
gross=`echo "$wage*$hours" | bc`
echo "Gross wages: $" $gross

elif [[ $Type -eq $two ]];
then
echo "He is an Hourly employee"
echo "Enter hourly wage: "
read wage
echo "Enter hours worked this week: "
read hours
gross=`echo "$wage*$hours" | bc`
echo "Gross wages: $" $gross
elif [[ "$Type" -eq $three ]];
then
echo "He is an Commission employee"
echo "Enter hourly wage: "
read wage
echo "Enter hours worked this week: "
read hours
gross=`echo "$wage*$hours" | bc`
sed -i.back
echo "Gross wages: $" $gross
else
echo "Unknown value for Type: $Type"
 
fi
#done
fi


andrewthomas 11-06-2013 07:23 PM

This sounds like a homework problem, no?

evo2 11-06-2013 07:47 PM

Hi,
Quote:

Originally Posted by andrewthomas (Post 5059721)
This sounds like a homework problem, no?

possibly.

We tried to help OP with this script over at http://www.linuxquestions.org/questi...on-4175483546/...

OP: again, please indent your code correctly (if you don't know what that means, either look it up or ask).

As for writing to files in a shell script, the simple way is to redirect the output of echo, using > or >> operators. Have a search online. Eg "bash output redirection".

Evo2.


All times are GMT -5. The time now is 06:02 PM.