-1

I'm writing a bash script. The output of this bash script is a config file which I create from a template file. I would like to use a sed command where I can specify ###member### as a match pattern, and AA as the replacement. But when I create a new config file with a new replacement BB, the old string AA is overwritten. I don't want to overwrite that old string AA; I just need to add BB behind AA.

EXAMPLE:

members     ###members###

members     aa, bb, cc, ...

I don't know if I can achieve this task with the sed command.

khelwood
  • 55,782
  • 14
  • 81
  • 108
nkode
  • 1
  • 5
    What's your actual input and the expected output? – Avinash Raj Sep 30 '14 at 07:43
  • 1
    Did you go through this? http://stackoverflow.com/questions/5171901/sed-command-find-and-replace-in-file-and-overwrite-file-doesnt-work-it-empties – iqstatic Sep 30 '14 at 07:53
  • what do you already try ? – NeronLeVelu Sep 30 '14 at 08:44
  • My actual input is from my template file where is line members and string for replace ###members###. Output file should looks like members AA. And then i create new config file from my template file and output file should looks like members AA, BB ... – nkode Sep 30 '14 at 08:58

1 Answers1

0

This might work for you (GNU sed):

sed '/###members###/{:a;N;/aa/s//&BB/;Ta}' file

Look for a line containing ###members### then append following lines to it until those lines contain aa and then append BB to aa.

potong
  • 55,640
  • 6
  • 51
  • 83