Sponsored Content
Homework and Emergencies Homework & Coursework Questions [Scripting]Find & replace using user input then replacing text after Post 302371618 by SlapnutsGT on Sunday 15th of November 2009 11:24:15 PM
Old 11-16-2009
[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:
Borrower's name:
After reading the name of the auto part and the borrower's name, this option
should verify that the auto part exists and that it is checked in. If so, the status
should be changed in the database, otherwise an error message should be
generated. The system date should be used to update the checkout date.

Basically I have an entry in the file that lists the parts (auto.parts)
i.e
Brakes:Frank:in::

What needs to happen is someone goes to "check out" the part, they enter the part name then the borrower's name and then the date, then I need to have it edit auto.parts to reflect the person who borrowed the part and the date they borrowed it on.

Brakes:Frank:in:0:na

turns into

Brakes:FrankSmilieut:11/25/09:Mike

2. Relevant commands, code, scripts, algorithms:
Trying to use some variation of sed to do this

sed -i -e "/$copart/s/<old>/<new>/g" auto.parts

3. The attempts at a solution (include all code and scripts):

So far I have:
...roughly...
Code:
echo "Part to be checked out:"
read copart
echo "Enter date:"
read codate
echo "Enter borrower's name:"
read bname

here is where im stuck I'm trying to use sed with something along the lines of:

Code:
sed -i -e "/$copart/s/in/out/g" -e "/$copart/s/0/$codate/g" -e "/$copart/s/na/$bname/g" auto.parts

I want it to find he line that has $copart in it then change the two fields with 0 to the date and na to borrower's name.

I know the way im changing my date isn't how it is said in the instructions but im trying to get over this first hurdle before tackling that issue.

I've been chugging at this on my own scouring the net for HOURS not having any luck finding anything (anything I'm able to comprehend at this point my brain is fried) I'm **hoping** I can get some insight here.. im getting desperate

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Georgia State University | Atlanta, GA USA | Fasheng Qiu CSc 3320

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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... (0 Replies)
Discussion started by: georgefurbee
0 Replies

2. Shell Programming and Scripting

find & replace with user input

Trying to create a script/executable to replace "abc" text string in "myfile.htm" with input from a pop-up field. For example, launch this thing and a prompt is popped up asking the user to input what "abc" should be replaced with, then it inserts what the user inputs in place of abc in the... (3 Replies)
Discussion started by: mike909
3 Replies

3. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

4. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

Hi, I have a folder which contains multiple config.xml files and one input file, Please see the below format. Config Files format looks like :- Code: <application name="SAMPLE-ARCHIVE"> <NVPairs name="Global Variables"> <NameValuePair> ... (0 Replies)
Discussion started by: haiksuresh
0 Replies

5. Shell Programming and Scripting

Search & Replacing text within a file

Hi all! I'm a newbie and I'm writing a script which will ask a user for data to search. I will then search for this data using grep and displaying this data back to the screen for the user to see. The user will then enter new data to replace the data searched. Now how do I replace this data... (4 Replies)
Discussion started by: macastor
4 Replies

6. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

7. 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

8. Shell Programming and Scripting

Finding a text in files & replacing it with unique strings

Hallo Everyone. I have to admit I'm shell scripting illiterate . I need to find certain strings in several text files and replace each of the string by unique & corresponding text. I prepared a csv file with 3 columns: <filename>;<old_pattern>;<new_pattern> ... (5 Replies)
Discussion started by: gordom
5 Replies

9. Shell Programming and Scripting

How-To Check & Filter user input

Hi, On my Java webpage which invokes the shell script has two checkboxes viz ... apache and weblogic apache require one parameter i.e apache home from the user while Weblogic requires three or five params from the user vi.z weblogic_home or <jdk_home, config_home & pid>, username and... (4 Replies)
Discussion started by: mohtashims
4 Replies

10. Programming

find & Replace text using two non-unique delimiters.

I can find and replace text when the delimiters are unique. What I cannot do is replace text using two NON-unique delimiters: Ex., "This html code <text blah >contains <garbage blah blah >. All tags must go,<text > but some must be replaced with <garbage blah blah > without erasing other... (5 Replies)
Discussion started by: bedtime
5 Replies
Prophet::CLI::TextEditorCommand(3pm)			User Contributed Perl Documentation		      Prophet::CLI::TextEditorCommand(3pm)

   separator_pattern
       A pattern that will match on lines that count as section separators in record templates. Separator string text is remembered as $1.

   comment_pattern
       A pattern that will match on lines that count as comments in record templates.

   build_separator $text
       Takes a string and returns it in separator form. A separator is a line of text that denotes a section in a template.

   build_template_section header => '=== foo ===' [, data => 'bar']
       Takes a header text string and (optionally) a data string and formats them into a template section.

   try_to_edit template => $tmpl [, record => $record ]
       Edits the given template if possible. Passes the updated template in to process_template (errors in the updated template must be handled
       there, not here).

   handle_template_errors error => 'foo', template_ref => $tmpl_str, bad_template => 'bar', rtype => 'ticket'
       Should be called in "process_template" if errors (usually validation ones) occur while processing a record template. This method prompts
       the user to re-edit and updates the template given by "template_ref" to contain the bad template (given by the arg "bad_template" prefixed
       with the error messages given in the "error" arg. If an errors section already exists in the template, it is replaced with an errors
       section containing the new errors.

       If the template you are editing is not section-based, you can override what will be prepended to the template by passing in the
       "errors_pattern" argument, and passing in "old_errors" if a template errors out repeatedly and there are old errors in the template that
       need to be replaced.

       Other arguments are: "rtype": the type of the record being edited. All arguments except overrides ("errors_pattern" and "old_errors" are
       required.

calling code must implement
       run process_template

perl v5.10.1							    2009-08-17				      Prophet::CLI::TextEditorCommand(3pm)
All times are GMT -4. The time now is 11:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy