Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This is in Unix Shell Scripting. using Putty.exe
The application I'm working on is to add,remove and update the information of a person.I need help to create a file config.bat so it will automatically create the person's ID number.
I would like to start from 1000 then add 1 everytime I add a person. This is the code I have to add the person. I'm missing the ID number.answer=y
while [ "$answer" = y ]
do
clear
echo -e "First Name: \b\c "
read first
clear
echo -e "Last Name: \b\c"
read last
clear
echo -e "M: \b\c "
read m
clear
echo -e "Street: \b\c"
read street
clear
echo -e "City: \b\c"
read city
clear
echo -e "State: \b\c"
read state
clear
echo -e "Zipcode: \b\c"
read zip
echo -e "Telephone: \b\c"
read phone
echo "$first:$last:$m:$street:$city:$state:$zip:$phone" >> store_data.txt
echo -e "Any more to add? (Y)es or (N)o> _\b\c"
read answer
case $answer in
[Yy]* ) answer=y ;;
* ) answer=n ;;
esac
done...thanks.

when u run the program for the first time, add 1000 as ID and keep adding one each time it runs.. i haven't tested this piece of code but u can work around to it...
tail -2 store_data.txt| head -1 | awk -F :'{print $1}' | read return
expr $return + 0 >/dev/null 2>&1
if [ $? -ne 0 ]
then
id=1000
else
if [ $return -gt 0 -a $return -lt 9999999 ]
then
id=$return+1
fiecho "$id:$first:$last:$m:$street:$city:$state:$zip:$phone" >> store_data.txt
Regards,
Devaraj Takhellambam

inlcude this piece of code
tail -1 store_data.txt | awk -F: '{print $1}'| read return
expr $return + 0 >/dev/null 2>&1
if [ $? -ne 0 ]
then
id=1000
elif [ $return -gt 0 -a $return -lt 9999999 ]
then
id=`expr $return + 1`
fi
echo $id
Regards,
Devaraj Takhellambam

Thanks for your help. On the same application i have to search the person with the id i entered.and display the info only by id.I will post the code on the search part, thanks again.

I need some help please. I did try the code above but it didn't work. Can someone tell me what am i doing wrong. Thanks.
return=`tail -1 store_data.txt | awk -F : '{ print $1 }'`
if [ $return == "" ]
then
id=1000
else
if [ $return -gt 0 -a $return -lt 9999999 ]
then
id=`expr $return + 1`
fi
fi

![]() |
awk 3 files together
|
comparing two files using...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |