Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. (a) Write a shell script, called delimit, that removes from each line of a file the first occurrence of a text string
  2. between an opening and closing delimiter. The specified delimiters are exactly one character, cannot be
  3. the same character, and nested delimiters are ignored. Assume the following characters are not used as the
  4. opening or closing delimiter: [ ] ^ $ .
  5. *
  6. / \. The script must handle an arbitrarily long list of input files.
  7. Print each input-file name on a separate line using the format “### filename ###” followed by the contents
  8. of the entire file with lines modified as appropriate. The script has the following interface:
  9. delimit opening-delimiter closing-delimiter input-file-list
  10. For example, for input files:CS 246 - Assignment 1 3
  11. $ cat input1.txt
  12. (abc)
  13. aa (a(d)xe)) (b) (c)fff
  14. asdf(aakk
  15. e)zz (ala)oe
  16. $ cat input2.txt
  17. abc(123
  18. the output from the command is:
  19. $ delimit
  20. )
  21. (
  22. input1.txt input2.txt
  23. ### input1.txt ###
  24. aa xe)) (b) (c)fff
  25. asdf(aakk
  26. e)zz oe
  27. ### input2.txt ###
  28. abc(123
  29. Hint, use the sed command to find and edit the lines of a file.
  30. Modify the delimit script to have a -i option that means generate the inverse output without the delimiters;
  31. i.e., it only prints the text-string and no delimiters. For example, the output from the command is:
  32. $ delimit -i
  33. )
  34. (
  35. input1.txt input2.txt
  36. ### input1.txt ###
  37. abc
  38. a(d
  39. ala
  40. ### input2.txt ###
  41. Hint, sed has a mechanism to store and use parts of a matched pattern.
  42. Solve and test the first part of the question, and then add and test the second part of the question. Only
  43. hand in a single script containing the solution to both parts; but if you cannot complete the second part,
  44. still hand in the solution to the first part.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement