Guest User

Untitled

a guest
Jun 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. sed_inplace_arg = "-i"
  2. sed_inplace_arg_darwin = "-i ''"
  3. sed_extended_re_arg = "-r"
  4. sed_extended_re_arg_darwin = "-E"
  5. sed () {
  6. # Sed portability notes
  7. # - SuSv3
  8. # - Only -e, -f, and -n are standard options
  9. # - Linux
  10. # - -i argument is of the form -i[ext]
  11. # - extended regular expressions argument is -r
  12. # - Mac OSX
  13. # - -i argument is of the form -i [ext]
  14. # - extended regular expressions argument is -E
  15. #
  16. # Here we support a limited subset of the available sed capabilities,
  17. # ensuring that all those supported by this function can be utilized
  18. # regardless of the current platform.
  19. #
  20. # We accept -n, -e, -f, and -i with no backup extension. We support
  21. # extended regular expressions using the -r argument. Note that extended
  22. # regular expressions support may not be retained, depending upon the
  23. # capabilities of the other platforms we wish to support, and we may need
  24. # to reimplement -i internally in this script on some platforms.
  25.  
  26. args=`getopt ner:f:i "$@"` || return 1
  27. set -- $args
  28.  
  29. opts=""
  30. while [ $# -gt 0 ]; do
  31. case $1 in
  32. -i)
  33. opts="$opts ${sed_inplace_arg}"
  34. ;;
  35. -r)
  36. opts="$opts ${sed_extended_re_arg}"
  37. ;;
  38. --)
  39. shift
  40. break
  41. ;;
  42. *)
  43. opts="$opts \"$1\""
  44. ;;
  45. esac
  46. shift
  47. done
  48. eval command sed $opts "$@"
  49. }
Add Comment
Please, Sign In to add comment