Replacing part of a text file with user input.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replacing part of a text file with user input.
# 1  
Old 04-11-2009
Replacing part of a text file with user input.

Ok, I am brand new to UNIX and I am trying to learn a cross between basic script and database use. I had got some ideas off the net on simple ideas for learning UNIX. I am working on creating a simple phone book program that allows myself to enter our employees from work into a phone book text file. I got this idea from school syllabus online. I didn't know it would be so hard. Anyways I made a basic menu, can remove names from the text file, can add names to the text file, but can not for the life of me figure out how to change one if I type it in wrong or a name change or something. When I add the user records it is like as follows:
$name:$address:$city:$state:$zipcode:$phone

The change program in short is as follows:
# I enter the name (George) and a record or records show up.
# I select the by number which is assigned by grep
grep -in "$name" phonebook|sed -n-e 's/^/\
/' -e 's:/\
/gp'
#now George is selected by a number record...ie...3
# and George is stored as a record in this program.
echo "Enter the record you want to change: \c"
read record
echo "You have selected the following record: \c"
sed -n -e "$record"p phonebook:sed -n -e 's/^/\
/' -e 's/:/\
/gp'
file=`sed -n "$record"p phonebook`
name=`echo $file | cut -d: -f1`
address=`sed $file | cut -d: -f2`
# I do the same for all of fields.. city, state, zip, phone...
#then I prompt the user if they would like to change the name, #address..etc if yes then the following code is in a if statment.
if [ "$ans" = "y" ]
then
echo "Enter new name: \c"
read newname
name=newname
fi

now I am not sure how to get it to over write the old record or create a new one and remove the old record.

Thanks
George
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Awk replacing file with user input

this section of the awk code i have here takes file to work with from the user. the user specifies the file name from the command line and the file name is assigned to the variable $FLIST awk 'BEGIN { while((getline < "'${FLIST}'")>0) S FS="\n"; RS="}\n" } now, i dont want... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

matching user input to a text file loop?

until do read -p "Invalid cars. Try againa" cars1 done Ok i have the above code, im getting users input and if it doesnt match in the file the user has to try again untill its correct But when i run this it gives me an error saying ./Cars.bash: line 43: (2 Replies)
Discussion started by: gangsta
2 Replies

4. UNIX for Dummies Questions & Answers

How to read a line of text from user input?

Hiii I wanna a read a line of text from standard input. The user enter data like this way name phone_no month1_salary month2_salary that is user enter the name ,phone no and salary of 2 months in a single line by giving spaces. I wanna add the 3rd and 4th fields ...ie add both... (4 Replies)
Discussion started by: krishnampkkm
4 Replies

5. Shell Programming and Scripting

Replacing some part of file

Hello, I have two files, consider that as file1 and file2. Here file1 is the master file. file1 will contain data like GS*RA*071000013*102562451P*091130*0520*334052023*X*003050 ST*820*334052023 BPR*C*509.77*C*ACH*CTX*01*071000013*DA*5529085*9000002008**01*071000013*DA*5529085*091130... (8 Replies)
Discussion started by: atlantis
8 Replies

6. Homework & Coursework Questions

[Scripting]Find & replace using user input then replacing text after

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: (o) Checkout an auto part: should prompt the user for the name of the auto part and borrower's name: Name:... (2 Replies)
Discussion started by: SlapnutsGT
2 Replies

7. Shell Programming and Scripting

Replacing data of output file with input

Hi, I have a ksh which peocess and get me data from 3 days... ie if i process it on jan 28.. it gets data for 25, 26 and 27.... the process run every day and get previous 3 days data...all this data is appened to a file lets call time.out Now time.out cannot have deplicate data so what i want... (10 Replies)
Discussion started by: bhagya2340
10 Replies

8. Shell Programming and Scripting

replacing spaces with null or 0 in the input file

hi i have records in my input file like this aaa|1234||2bc||rahul|tamilnadu bba|2234||b4c||bajaj|tamilnadu what i am expecting is in between two pipes if there is no character it should be replaced with null or 0 so my file will look like this aaa|1234|null|2bc|0|rahul|tamilnadu... (4 Replies)
Discussion started by: trichyselva
4 Replies

9. Shell Programming and Scripting

replacing text in a file, but...

Hi all, Very first post on this forums, hope you can help me with this scripting task. I have a big text file with over 3000 lines, some of those lines contain some text that I need to replace, lets say for simplicity the text to be replaced in those lines is "aaa" and I need it to replace it... (2 Replies)
Discussion started by: Angelseph
2 Replies

10. Shell Programming and Scripting

Replacing the part of file name?

Hi All One of my script generate following files. These files has static TIMESTAMP 20080227. AccAdd_20080227_1000.dat AccBal_20080227_1000.dat Acc_20080227_1000.dat AccGrpMem_20080227_1000.dat AccToCust_20080227_1000.dat What i need to do is, once the file has been generated, it... (7 Replies)
Discussion started by: Amit.Sagpariya
7 Replies
Login or Register to Ask a Question