Objective: Remove instances of the 'nis' string only from these two lines: 'passwd: files nis sss' and 'group: files nis sss' at /path/to/nsswitch.conf (some other 'nis' strings exist at the 'group: files nis sss' line and elsewhere... so we'll leave them as is and narrow down the hits to the '^passwd' and '^shadow' lines only) and call the string-manipulation command/s via sudo. Any way to keep the whitespaces or tab stops when I use /usr/bin/ex? [foo@jumpspeeder ~]$ echo 'passwd: files nis sss' >~/nsswitch.conf [foo@jumpspeeder ~]$ cat ~/nsswitch.conf passwd: files nis sss ^ | | Look here... [foo@jumpspeeder ~]$ ex -s -c '%s/^\(passwd:\|shadow:\) \+\(files\) \+nis \+\(sss\)/\1 \2 \3/' -c w -c q ~/nsswitch.conf [foo@jumpspeeder ~]$ cat ~/nsswitch.conf passwd: files sss ^ | | ...here too. Thanks in advance.