| | |
File doesn't update data
![]() |
•
•
Join Date: Oct 2008
Posts: 40
Reputation:
Solved Threads: 0
Good afternoon all!
I am writing an address book for a class that I have, and am stuck on this last part. Any help would be greatly appreciated!
When the user selects the "Edit existing record" option, I can't figure out how to make the file overwrite the previous record. As it stands now, it makes a new record with the new data, leaving the old record intact.
Currently written in bash.
Thank you in advance for your assistance!
Again, thank you for taking the time to point out my error(s)
- Jim
I am writing an address book for a class that I have, and am stuck on this last part. Any help would be greatly appreciated!
When the user selects the "Edit existing record" option, I can't figure out how to make the file overwrite the previous record. As it stands now, it makes a new record with the new data, leaving the old record intact.
Currently written in bash.
Thank you in advance for your assistance!
Shell Scripting Syntax (Toggle Plain Text)
3) echo echo "You have chose to Edit an Existing Entry" echo "Enter part or all of a name/phone# or address" echo read search choiceLine=`grep -i "$search" addressbook.txt` oldName=`echo $choiceLine|cut -d ":" -f1` oldPhone=`echo $choiceLine|cut -d ":" -f2` oldAddress=`echo $choiceLine|cut -d ":" -f3` echo "You have chosen to search for : $search" grep -v "$search" addressbook.txt > addressbook.tmp echo "If you don't wish to change the name, press enter" echo -n "The name [ $oldName ] will be changed to: " read name if [ -z "$name" ]; then name=$oldName fi echo "The previous phone number was: $oldPhone" echo "If you don't wish to change the number, press enter" echo -en "Please enter a new phone number: " read phone if [ -z "$phone" ]; then phone=$oldPhone fi echo "The previous address was: $oldAddress" echo "If you don't wish to change the address, press enter" echo -en "Please enter a new address: " read address if [ -z "$address" ]; then address=$oldAddress fi echo "${name}:${phone}:${address}" >> addressbook.txt ;;
Again, thank you for taking the time to point out my error(s)
- Jim
Last edited by JimD C++ Newb; Mar 3rd, 2009 at 3:31 pm.
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
Hey There,
Also, at the end of your code if you change:
to
should inline replace the file.
Hope that helps
, Mike
Also, at the end of your code if you change:
Shell Scripting Syntax (Toggle Plain Text)
echo "${name}:${phone}:${address}" >> addressbook.txt
to
Shell Scripting Syntax (Toggle Plain Text)
echo "${name}:${phone}:${address}" > addressbook.txt
should inline replace the file.
Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Similar Threads
- how to update data in mysql table using data from an excel table (MySQL)
- How to update data in a text file? (C++)
- Data View (Python)
- conversion of text file into data base file (Visual Basic 4 / 5 / 6)
- File Processing C++ (C++)
- Saving to a file (C)
- Sequential Access Data Files (Visual Basic 4 / 5 / 6)
- Reading from external data file (C++)
- How can I read from a txt file? (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: useradd question
- Next Thread: Create a directory with current date
| Thread Tools | Search this Thread |





