I have been trying to add a string in the same line in a text file. I have used following method.
sed -i "s/\bmembers\b/& \t$host,/" printer.cfg
It will add a string after members string and also it will add tab in order to make it proper.
I will get result like this,
define hostgroup{
hostgroup_name HOSTGROUP ONE
alias Host Group 1 Printers
members foo0, foo1, bar2, foo2, bar3
}
Where foo0 is my added string using above sed.
But the problem is there is one text file, that contains many "members" string.
e.g.
define hostgroup{
hostgroup_name HOSTGROUP ONE
alias Host Group 1 Printers
members foo1, bar2, foo2, bar3
}
define hostgroup{
hostgroup_name HOSTGROUP TWO
alias 2nd Host Group
members example1, example3, example2
}
In this above example, I want to add string ONLY in first para (hostgroup_name HOSTGROUP ONE). In this case, How can I refer hostgroup_name and add text after "members" string with one tab?