Home > other >  using sed command subtitution
using sed command subtitution

Time:12-05

How to only specific value substitute in sed command

for example,

Linux system
Windows syste
Mac    syste

I tried this command

sed 's/syste/system/g' file.txt

safwanpaloli@hello:~/linx$ sed 's/syste/system/g' new.txt 
Linux systemm
Windows system
Mac   system

I expected result

Linux system
Windows system
Mac   system

CodePudding user response:

Try sed 's/system/syste/g;s/syste/system/g' new.txt.

CodePudding user response:

You can try this sed which will match the last word and replace with system

$ sed 's/[a-zA-Z]*$/system/g' input_file
Linux system
Windows system
Mac   system

CodePudding user response:

Substitute the m too, but only if it's there.

sed 's/system\?/system/g'
  • Related