Computing.Net > Forums > Unix > how to create config.bat file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

how to create config.bat file

Reply to Message Icon

Name: qakalla
Date: November 17, 2006 at 17:11:11 Pacific
OS: XP
CPU/Ram: 2.8
Product: HP
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Devaraj (by Fidy)
Date: November 17, 2006 at 19:04:10 Pacific
Reply:

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
fi

echo "$id:$first:$last:$m:$street:$city:$state:$zip:$phone" >> store_data.txt


Regards,
Devaraj Takhellambam


0

Response Number 2
Name: qakalla
Date: November 17, 2006 at 21:18:46 Pacific
Reply:

Thanks a lot Fidy, I will try to run the code tom..


0

Response Number 3
Name: Devaraj (by Fidy)
Date: November 20, 2006 at 00:38:52 Pacific
Reply:

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


0

Response Number 4
Name: qakalla
Date: November 20, 2006 at 21:17:04 Pacific
Reply:

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.


0

Response Number 5
Name: qakalla
Date: November 26, 2006 at 16:58:06 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

awk 3 files together comparing two files using...



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: how to create config.bat file

how to create TAR files www.computing.net/answers/unix/how-to-create-tar-files/3978.html

How To create resolve.conf file www.computing.net/answers/unix/how-to-create-resolveconf-file/5986.html

How to create a file with extension www.computing.net/answers/unix/how-to-create-a-file-with-extension/7595.html