Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (a) Write a shell script, called delimit, that removes from each line of a file the first occurrence of a text string
- between an opening and closing delimiter. The specified delimiters are exactly one character, cannot be
- the same character, and nested delimiters are ignored. Assume the following characters are not used as the
- opening or closing delimiter: [ ] ^ $ .
- *
- / \. The script must handle an arbitrarily long list of input files.
- Print each input-file name on a separate line using the format “### filename ###” followed by the contents
- of the entire file with lines modified as appropriate. The script has the following interface:
- delimit opening-delimiter closing-delimiter input-file-list
- For example, for input files:CS 246 - Assignment 1 3
- $ cat input1.txt
- (abc)
- aa (a(d)xe)) (b) (c)fff
- asdf(aakk
- e)zz (ala)oe
- $ cat input2.txt
- abc(123
- the output from the command is:
- $ delimit
- ′
- )
- ′
- ′
- (
- ′
- input1.txt input2.txt
- ### input1.txt ###
- aa xe)) (b) (c)fff
- asdf(aakk
- e)zz oe
- ### input2.txt ###
- abc(123
- Hint, use the sed command to find and edit the lines of a file.
- Modify the delimit script to have a -i option that means generate the inverse output without the delimiters;
- i.e., it only prints the text-string and no delimiters. For example, the output from the command is:
- $ delimit -i
- ′
- )
- ′
- ′
- (
- ′
- input1.txt input2.txt
- ### input1.txt ###
- abc
- a(d
- ala
- ### input2.txt ###
- Hint, sed has a mechanism to store and use parts of a matched pattern.
- Solve and test the first part of the question, and then add and test the second part of the question. Only
- hand in a single script containing the solution to both parts; but if you cannot complete the second part,
- still hand in the solution to the first part.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement