Re: Replace line in file based on pattern

2022-01-15 Thread Andrei POPESCU
On Du, 02 ian 22, 21:22:33, Paul M. Foster wrote: > > I'm not interested in hacking a bunch of servers. Just one. The whole > purpose here is to restore a system to more or less its original > configuration when a reinstall must occur. A reinstall must occur when there > is a severe hardware failu

Re: Replace line in file based on pattern

2022-01-04 Thread David Wright
On Mon 03 Jan 2022 at 08:38:32 (-0500), Paul M. Foster wrote: > On 1/2/22 11:03 PM, Greg Wooledge wrote: > > On Sun, Jan 02, 2022 at 09:59:08PM -0500, Paul M. Foster wrote: > > > Regarding "patch", let's consider a "stock" config file from a fresh > > > install > > > (call it NEW), and an existing

Re: Replace line in file based on pattern

2022-01-03 Thread Paul M. Foster
On 1/2/22 11:03 PM, Greg Wooledge wrote: On Sun, Jan 02, 2022 at 09:59:08PM -0500, Paul M. Foster wrote: Regarding "patch", let's consider a "stock" config file from a fresh install (call it NEW), and an existing config which is tweaked for my purposes (call it OLD). Assume I want the stock conf

Re: Replace line in file based on pattern

2022-01-02 Thread john doe
On 1/3/2022 2:56 AM, Paul M. Foster wrote: On 1/2/22 6:20 PM, The Wanderer wrote: On 2022-01-02 at 17:52, Paul M. Foster wrote: Folks: In a script, I'd like to search for a pattern in a file, and replace that line entirely with a new line, once (not globally). I've tried What do you mean by

Re: Replace line in file based on pattern

2022-01-02 Thread Greg Wooledge
On Sun, Jan 02, 2022 at 09:59:08PM -0500, Paul M. Foster wrote: > Regarding "patch", let's consider a "stock" config file from a fresh install > (call it NEW), and an existing config which is tweaked for my purposes (call > it OLD). Assume I want the stock config altered to conform to my > existing

Re: Replace line in file based on pattern

2022-01-02 Thread Paul M. Foster
On 1/2/22 6:40 PM, Greg Wooledge wrote: On Sun, Jan 02, 2022 at 06:20:15PM -0500, The Wanderer wrote: Of course, given the ORIGINAL question, the best tool is neither of these. It's something like ansible or puppet. Or if you insist on jury-rigging crap together with stone knives and bearskin

Re: Replace line in file based on pattern

2022-01-02 Thread Paul M. Foster
On 1/2/22 8:46 PM, Greg Wooledge wrote: I'm rearranging the order of the quoted sections. On Sun, Jan 02, 2022 at 08:14:47PM -0500, The Wanderer wrote: That's very interesting, although not all that accessible to the relative newcomer to the field. It does leave me sad about the apparent conclu

Re: Replace line in file based on pattern

2022-01-02 Thread Paul M. Foster
On 1/2/22 6:20 PM, The Wanderer wrote: On 2022-01-02 at 17:52, Paul M. Foster wrote: Folks: In a script, I'd like to search for a pattern in a file, and replace that line entirely with a new line, once (not globally). I've tried What do you mean by "globally"? "Globally" just means I want

Re: Replace line in file based on pattern

2022-01-02 Thread Paul M. Foster
On 1/2/22 6:18 PM, Andy Smith wrote: Hello, On Sun, Jan 02, 2022 at 05:52:36PM -0500, Paul M. Foster wrote: In a script, I'd like to search for a pattern in a file, and replace that line entirely with a new line, once (not globally). I've tried sed -i s/search/new_line/ but this only replaces

Re: Replace line in file based on pattern

2022-01-02 Thread Greg Wooledge
I'm rearranging the order of the quoted sections. On Sun, Jan 02, 2022 at 08:14:47PM -0500, The Wanderer wrote: > That's very interesting, although not all that accessible to the > relative newcomer to the field. It does leave me sad about the apparent > conclusion that there is no safe way to edi

Re: Replace line in file based on pattern

2022-01-02 Thread The Wanderer
On 2022-01-02 at 18:40, Greg Wooledge wrote: > On Sun, Jan 02, 2022 at 06:20:15PM -0500, The Wanderer wrote: > >> If you mean that you want to only replace the first matching line >> in the file, but leave any subsequent matching lines alone... I've >> never actually had occasion to do that, but

Re: Replace line in file based on pattern

2022-01-02 Thread Greg Wooledge
On Sun, Jan 02, 2022 at 06:20:15PM -0500, The Wanderer wrote: > If you mean that you want to only replace the first matching line in the > file, but leave any subsequent matching lines alone... I've never > actually had occasion to do that, but a bit of Googling (for 'sed first > match only') found

Re: Replace line in file based on pattern

2022-01-02 Thread The Wanderer
On 2022-01-02 at 17:52, Paul M. Foster wrote: > Folks: > > In a script, I'd like to search for a pattern in a file, and replace > that line entirely with a new line, once (not globally). I've tried What do you mean by "globally"? If you mean that you want to only replace the first matching line

Re: Replace line in file based on pattern

2022-01-02 Thread Andy Smith
Hello, On Sun, Jan 02, 2022 at 05:52:36PM -0500, Paul M. Foster wrote: > In a script, I'd like to search for a pattern in a file, and replace that > line entirely with a new line, once (not globally). I've tried > > sed -i s/search/new_line/ > > but this only replaces the string itself. I want t