0

I am trying to make the following changes to my files:

grep -rl 'arg_1 :' . | xargs sed  -i 's/arg_1 :/arg_1:/g'

That is, I am looking to replace arg_1 : with arg_1:

However when I run this same argument, I get the following error:

sed: 1: "./ua/uaosfamily.md": invalid command code .

If I replace. by the absolute path, I get the following error:

sed: 1: "/Users/josemanueldefrut ...": invalid command code j

I understand that in passing. as an argument it is not evaluated as the absolute path and therefore the fault arises. Could someone explain to me why this happens and how can it be solved?

Jose Manuel de Frutos
  • 1,040
  • 1
  • 7
  • 19
  • 2
    Maybe your sed needs an extension argument after `-i`? – choroba Nov 10 '21 at 17:13
  • 6
    You are on macOS/freebsd where the required syntax is `sed -i extension pattern file`. You are trying to run `sed -i pattern file` which is only valid on GNU. Add the additional argument, e.g. `.. | xargs sed -i .bak 's/arg_1 :/arg_1:/g'`, and try again. – that other guy Nov 10 '21 at 17:20

1 Answers1

0

Indeed it is what was commented previously. It seems that sed on mac has a different syntax. It seems that this question was already asked.

sed command with -i option failing on Mac, but works on Linux

Jose Manuel de Frutos
  • 1,040
  • 1
  • 7
  • 19