Which would substitute a string for a replacement

Assignment Help Computer Engineering
Reference no: EM1336611

How would I write a shell script, change-lines, which will substitute a string for a replacement string for each occurance of the string in files specified? The original file will be saved, with the same filename with the. keep extension unless the -n option is present. I don't mind using temporary file for this script. The search string and/or the replacement string can have special characters in them.

The script will use

* the option -s "string" for the search string
* the option -r "string" for the replacement string
* the -n option to prevent a backup file from being created
* the -h option to print a usage statement and exit

The script will exit with an error status and print an error message:

* if the -s option is not present.
* if the -r option is not present.
* if the string is not specified with the -s option
* if the string is not specified with the -r option
* if there are any other options specified
* if there are no input files specified
* if the input file cannot be read by the current process
* if the input file cannot be written by the current process
* if you cannot create the backup file.

Here is the usage statement for the script:

change-lines [-n] -s search string -r replace string files ...

-n do not backup the original file
-s search string the search for this string
-r replace string replace the search string with this string
-h print this message

Examples:

prompt> change-lines -s foobar -r FooBar *.c
This script will edit all the files *.c, and each occurrence of foobar it will be replaced by FooBar it will be replaced by FooBar. Each file will be backed up.

prompt> change-lines -s "SHELL IS NOT FUN" -r "SHELL PROGRAMING IS A LOT OF FUN" /tmp/file1.txt
This script will edit all the file /tmp/file1.txt , and each occurrence of SHELL IS NOT FUN will replaced by the text, SHELL PROGRAMMING IS A LOT OF FUN. A backup file /tmp/file1.txt.keep will be created.

Reference no: EM1336611

Questions Cloud

Explain how does the size this effect depend on the volume : Explain how is Brazil affected, explain how does the size of this effect depend on the volume of trade between Brazil and the United States.
Explain poulation growth and sum of annuities : Explain Poulation Growth and Sum of annuities and What would the population in 1990 have been if growth had continued in this same pattern
Comparative analysis of relationships : Discuss in detail the three contextual relationships between drug use and crime using examples from the newspapers, internet, or other professional or public journals.
Determine efficiency : A plant has an effective capacity of 900 units per day and produces 600 units per day with its product mix; determine its efficiency?
Which would substitute a string for a replacement : How would I write down a shell script, change-lines, which will substitute a string for a replacement string for each occurance of the string in files specified? The original file will be saved, with the similar filename with the.
Explain product in the marketing mix : Explain Product in the marketing mix and describe the key points of a good or service as it applies to the piece of the marketing mix
Find the expected output : Find  the expected output for a plant with a design capacity of 108 chairs per day.
Elucidate why the mp-p relation is deficient : Elucidate why the MP/P relation is deficient as the sole mechanism for determining the optimal level of resource.
Discussing drugs and crime : What do you think has more effect on a person's inclination to abuse drugs: social factors or psychological factors?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Getters would provide access to the attributes.

For this task you will make a Subject class, whose instances will represent the subjects for study at a university. A subject will have a name, just a String, and a subject code, that is a six-character String.

  A word document with another office-type document

A compound document within Microsoft Office usually consists of a Word document with another office-type document (i.e. Excel, PowerPoint slideshow, etc.) within the Word document.

  Define five properties of controls

Are Integers and Strings considered objects in VB? Elaborate.

  What is missing, incomplete, inaccurate

Email clients have to enable SSL encryption both for POP and SMTP. That way regardless of where we work, our email traffic would not expose any data to network eavesdropping techniques.

  Create a program to perform the simulation

Each time a square is touched, the count for that square is incremented. Thus, a non-zero entry in the array shows the number of times bug has landed on the corresponding square. When every square has been touched at least once, the simulation is ..

  The difference between subnetting and supernetting

give the importance of subnetting with respect to collisions, broadcasts and controlling traffic. Discuss the difference between subnetting and supernetting.

  Make draft or a excel spreadsheet of java vs. c++

want a draft or a excel spreadsheet of Java vs. C++ and its comparisons. I want bold statements and strong related bold information.

  Determining the output

Specify the output if input is diamond diamond? State the output if the input is diamond gold?

  What are the trends towards marrying

express at least two different ways that database management software like Microsoft® Access® can help an organization avoid or reduce data-quality problems mentioned in the article.

  What the command does, how it might be used

What the command does, how it might be used.

  Estimatedrtt in terms of four sample rtts

For a provided TCP connection, assume four acknowledgments have been returned with corresponding sample RTTs SampleRTT4, SampleRTT3, SampleRTT2, and SampleRTT1. Express EstimatedRTT in terms of four sample RTTs.

  How to write a report on object-oriented systems

How to write a report on Object-Oriented Systems?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd