How would i write a shell script, change-lines

Assignment Help Programming Languages
Reference no: EM13948022

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: EM13948022

Questions Cloud

Behaviors impact the organization and why : What were the behaviors in each culture, and how did those behaviors impact the organization and why? Of the three organizational cultures, which one would you prefer to be a part of and why?
Find the mean and standard deviation of this population : find the mean and standard deviation of this population. List all possible swamples of size 2. Find the sample average for each sample.
From a group of 4 girls and 3 boys five persons are to be : From a group of 4 girls and 3 boys, five persons are to be selected to form a committee so that at least 3 girls are there on the committee. In how many ways can it be done?
What is the coefficient of variation of ima : What is the coefficient of variation of Ima's interest rate forecast?
How would i write a shell script, change-lines : 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?
Determine the voltage gain for the ce amplifier : Determine the voltage gain for the CE amplifier and determine the voltage gain and the power gain - the power dissipated in the transistor with no load.
What are examples of core measures of lead indicators : What are examples of core measures? Of lead indicators? What are the desired characteristics of measures in the government sector?
State the implications of this for managing strategic change : Is it inevitable that employees will respond to change with feelings of fear? If you believe the answer is yes, state the implications of this for managing strategic change.
Upgrade the workstation''s adapter cards to support 100 mbps. : You are to come up with a solution to support the high bandwidth applications and growth potential of this company.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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