Skip to main content
4 of 4
Grammar, syntax
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

Sed Command behavior difference wrt argument handling

Recently I was working on performing a sed operation on a config file. I found that the sed command is behaving differently with the parameter -ir vs -ri :-

[root@node system]# sed -ri 's|(^[[:space:]]+[Kk]ernel.*$)|\1 transparent_hugepage=never|' temp_file
[root@node system]# echo $?
0

[root@node system]# sed -ir 's|(^[[:space:]]+[Kk]ernel.*$)|\1 transparent_hugepage=never|' temp_file
sed: -e expression #1, char 60: invalid reference \1 on `s' command's RHS
[root@node system]# echo $?
1