1

When I try to do a S&R that is case insensitive using an I option at the end of the pattern s/find-word/replace-word/Ig, I get an error that the command is garbled. The exact same works if I run it without the I, i.e. s/find-word/replace-word/g. I am using Solaris 5.10, is it possible that our sed is old and does not support I?

Thanks

danorton
  • 11,804
  • 7
  • 44
  • 52
amphibient
  • 29,770
  • 54
  • 146
  • 240
  • duplicate of http://stackoverflow.com/questions/4412945/case-insensitive-search-replace-with-sed – michael Jun 29 '13 at 04:48
  • **EDIT:** Not a duplicate, just a poor title for the actual question asked, so I have changed the title, accordingly. The top answer seems to correctly answer the question, but the OP seems to have abandoned the question. – danorton Feb 21 '14 at 16:53

2 Answers2

9

I suggest using a lowercase i: s/from/to/gi


EDIT: Okay, me and my smartassery... According to http://www.unix.com/shell-programming-scripting/202109-sed-i-not-available-solaris-5-10-a.html and a lot of other links, seems like sed tool on solaris systems doesn't support the -i option... Best solution then would be to either use a busybox, rebuild GNU sed for your system, or use a perl script to do the work.

danorton
  • 11,804
  • 7
  • 44
  • 52
red
  • 3,163
  • 1
  • 17
  • 16
  • I was using a capital I because an example I had found instructed so. Tried lowercase as well but to no avail – amphibient Oct 02 '12 at 17:59
3

If your version of sed doesn't support the ignorecase flag, you might pre-lowercase all input with tr:

<infile tr 'A-Z' 'a-z' | sed ...
Thor
  • 45,082
  • 11
  • 119
  • 130
  • 1
    sed, awk and tr are the most difficult things to deal with on solaris when writing portable scripts; tr in this case doesn't necessarily help matters (formatting is a little hard in a comment, but I'll try): `$ type -ap tr` on my solaris 5.10 produces: ( `/bin/tr /usr/bin/tr /usr/ucb/tr /usr/xpg4/bin/tr /usr/xpg6/bin/tr` ), so beware : `$ for tr in $( type -ap tr ); do echo "$( echo AaBbCc | $tr 'A-Z' 'a-z' ) == $tr ..."; done` yields: `aaBbCc == /bin/tr ... aaBbCc == /usr/bin/tr ... aabbcc == /usr/ucb/tr ... AaBbCc == /usr/xpg4/bin/tr ... AaBbCc == /usr/xpg6/bin/tr ...` – michael Jun 29 '13 at 05:01
  • 1
    fyi, as long as not using `/usr/ucb/tr`, this works on the other `tr`'s: `tr '[:upper:]' '[:lower:]'`. Unfortunately, for portable scripts (even across different solaris boxes, with a different `PATH`), a script needs to test for which `tr` is being used, if you in fact need to use `tr`. (It's almost not worth it.) – michael Jun 29 '13 at 05:09