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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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