jeremyforan
jeremyforan

Reputation: 1437

Sed Statement not working Linux Raspbian

when issuing this command:

sed -i 's/"ExecStart=-/sbin/agetty --noclear %I $TERM"/"ExecStart=-/sbin/agetty --noclear -a root %I $TERM"/g' /lib/systemd/system/[email protected]

or

sed -i s/"ExecStart=-/sbin/agetty --noclear %I $TERM"/"ExecStart=-/sbin/agetty --noclear -a root %I $TERM"/g /lib/systemd/system/[email protected]

or

sed -i s/'ExecStart=-/sbin/agetty --noclear %I $TERM'/'ExecStart=-/sbin/agetty --noclear -a root %I $TERM'/g /lib/systemd/system/[email protected]

I get the following error:

sed -i 's/"ExecStart=-/sbin/agetty --noclear %I $TERM"/"ExecStart=-/sbin/agetty --noclear -a root %I $TERM"/g' /lib/systemd/system/[email protected]
sed: -e expression #1, char 21: unknown option to `s'

What am I doing wrong here?

Upvotes: 1

Views: 138

Answers (2)

Inian
Inian

Reputation: 85845

Change the de-limiter string from / to something else like ; when trying to replace character strings involving / in the substitution part.

sed -i.bak 's;"ExecStart=-/sbin/agetty --noclear %I $TERM";"ExecStart=-/sbin/agetty --noclear -a root %I $TERM";g' /lib/systemd/system/[email protected]

Upvotes: 1

Kent
Kent

Reputation: 195229

sed -i "s#ExecStart=-/sbin/agetty --noclear %I $TERM#ExecStart=-/sbin/agetty --noclear -a root %I $TERM#g"  /lib/systemd/system/[email protected]

The above line should go, give it a try!

Your problem:

  • should be in this format: "s/foo$var1/bar$var2/g"
  • if pattern/replacement has slash too, you have to either escape the s/../../ slash or use other separator.

Upvotes: 2

Related Questions