Why does the -i option/argument behave differently for sed and grep?

So when using the sed command in the terminal we have to write ‘-i’ in after sed to actually rewrite the file and change it. However, we use -i to specificy for the grep command that the search should be case insensitive. Why is -i used differently in these two instances. And further, how do we specifiy case sensitivity (or non-sensitivity) for sed?

These might be helpful:

https://www.gnu.org/software/sed/manual/html_node/Overview.html#Overview

-i when using the stream editor (sed) means you can edit the file in place
" sed writes output to standard output. Use -i to edit files in-place instead of printing to standard output"

-i in grep means ignore case distinctions when searching.

https://www.tutorialspoint.com/unix_commands/grep.htm

This also might be of use:
https://www.gnu.org/software/grep/manual/

1 Like

So how would you use sed such that it was or wasn’t case sensitive?

  • grep is used for searching and pattern matching in files.

  • sed is an editor (that works like regex, I guess) that searches for text that you want to change in files.

To make the search pattern case-insensitive I believe you use the “I” (that’s a capital letter I (eye) not a lowercase l (el) or the pipe, “|” character).

ex:
https://www.unix.com/unix-for-beginners-questions-and-answers/278208-making-sed-case-insensitive.html
And:
https://www.computerhope.com/unix/used.htm

If you have a Mac, OS, Catalina the capital letter “I” does not work:

https://stackoverflow.com/questions/4412945/case-insensitive-search-and-replace-with-sed#12887319

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.