0

I tried so many but it doesn't seem to work on macOS Terminal. My file contains the String this is an example zero to multiple times. After this the script should insert a new line followed by another String, for example this is an inserted line and safe it back to the original file (in concrete case the sudoers file should be modified).

I didn't got the participle of the syntax of sed on macOS, so I would be pleasured if I get a functional script with an understandable explanation. Thanks! :)

EDIT

Here's one sample command, the script should find %admin ALL=(ALL) ALL from the sudoers file, then insert a new line and the current account.

sudo cat /etc/sudoers | sed 'a/\%admin  ALL=(ALL) ALL\
testaccount  ALL=(ALL) ALL' > test.txt
1072
  • 57
  • 1
  • 6
  • Show us what you tried with `sed` and perhaps we'll be able to see where things went wrong. Also, in general a sample input and output file are very helpful for people trying to tell if they have the right solution for you or not – Eric Renouf Nov 25 '16 at 22:25
  • @EricRenouf Done. And to sample input: It's sudoers file. – 1072 Nov 25 '16 at 22:36
  • @EricRenouf It is no duplicate, because the script from this question created here an error `sed '/CLIENTSCRIPT="foo"/a CLIENTSCRIPT2="hello"' file sed: 1: "/CLIENTSCRIPT="foo"/a C ...": command a expects \ followed by text` – 1072 Nov 25 '16 at 23:26
  • That answer is for GNU sed, if you look at the next answer down it provides one that works with BSD sed as well, which should work on the Mac I expect – Eric Renouf Nov 25 '16 at 23:28

0 Answers0