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

  Discuss the purpose of the php procedures

Discuss the purpose of the PHP procedures that you have written.

  Write application to compute the total cost of new carpet

Write the application which computes the total cost of new carpet for a rectangular room. Application must first ask user for the current cost of the carpet per square foot. It then asks for both length.

  Write a test harness for these classes

Write an interface IClown that defines one method Honk(). Modify the TallGuyClown class to implement that interface so that calling Honk() will display a MessageBox (as above) that says "Honk my horn!". Add a property FunnyThingIHave to the interf..

  Design and implement program catches and handles exception

Design and implement a program that creates an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it.

  Methods to declare and initialize one dimensional arraay

What is an array? Show different methods to declare and initialize one dimensional array. Draw how an integer array of 6 elements having base address 5001 is stored in memory.

  Brief explanations for the solutions in the ms word file

You have a server-side script that cannot handle any ampersands (&) in the form data. Write a function that converts all ampersands in a form field to " and " when the field loses focus (onblur).

  Design and implement set of classes to model employees

Design and implement a set of classes to model the employees of a hospital: doctor, nurse, administrator, etc. Include methods in each class.

  Accuracy and completeness of computations

Analysis right and you have to develop a plausible argument to "prove" that your analysis is correct

  Design a math sorting game

Using Visual Studio 2010, design a math sorting game. A random number between 1 and 99 will be generated and displayed to the user. User will quickly have to divide that number by 3, and come up with remainder.

  Make confirmation page using xhtml portion of script

Use XHTML portion of the script to make confirmation page to be viewed by visitor. Confirmation page must display the text of email message.

  Using the irvine32 library functions

Create 32 random points which have (x, y) co-ordinates

  Write a program to enter series of numbers

Write a program that ask the user to enter a series of numbers ending with -1. After the -1 is input, program should print how many numbers are even and how many numbers are odd.

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