Re: Inserting Text In Specific Location Using Shell Script
- From: Wayne Betts <wbetts@xxxxxxx>
- Date: Fri, 26 May 2006 16:31:02 -0400
Cesar Covarrubias wrote:
Hello,Here's an example I think would work. It doesn't require much as far as the formatting of the files, other than the form of "#comment 2" which could be generalized with some regexp magic, but it sounds like you might not need anything so fancy:
I am running a script on about 30 machines and need to insert text after
a specific comment. For example:
#comment 1
#comment 2
#comment 3
I want to add text after #comment 2, on a new line. I have been trying
to work with both sed and awk but no success. This has to be done in
bash or sh and cannot be done in any other language. Any ideas?
Some prerequisites:
a file that contains the text to be inserted (eg. /path/to/insertme.txt)
the file in which the text is to be inserted (eg. /path/to/original.txt)
-----
#!/bin/sh
insertme="/path/to/insertme.txt"
original="/path/to/original.txt"
export INSERT=$insertme export ORIGINAL=$original
cat $original | gawk '{print $0; if ($0 == "#comment 2") system("cat $INSERT >> $ORIGINAL.mod");}' >> $original.mod
-----
This should produce the file /path/to/original.txt.mod, which you could then mv to original.txt, overwriting the original if desired.
(Sorry, I haven't tested this so I may have missed a quote mark or something, but that should be close.)
HTH,
- Wayne
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
- References:
- Inserting Text In Specific Location Using Shell Script
- From: Cesar Covarrubias
- Inserting Text In Specific Location Using Shell Script
- Prev by Date: Re: Inserting Text In Specific Location Using Shell Script
- Next by Date: background processes ?
- Previous by thread: RE: Inserting Text In Specific Location Using Shell Script
- Next by thread: Re: Inserting Text In Specific Location Using Shell Script
- Index(es):
Relevant Pages
- Re: Inserting Text In Specific Location Using Shell Script
... there are two ways that come to my mind to do this. ... I am running a script
on about 30 machines and need to insert text after ... Cesar Covarrubias ...
(RedHat) - Inserting Text In Specific Location Using Shell Script
... I am running a script on about 30 machines and need to insert text after ...
bash or sh and cannot be done in any other language. ... Cesar Covarrubias ...
(RedHat) - Re: Automating password change
... All the machines are set up differently from each other ... > use telnet,
others I can rlogin or remsh, and still others I can ssh. ... it would not be practical
to try to write a complex script ... > to write a simple script to wrap around passwd
that would run on each ... (comp.unix.solaris) - Re: Automating password change
... All the machines are set up differently from each other ... > use telnet,
others I can rlogin or remsh, and still others I can ssh. ... it would not be practical
to try to write a complex script ... > to write a simple script to wrap around passwd
that would run on each ... (comp.unix.shell) - RE: Another overflow exploit for Apache? *RESOLVED*
... You must be reviewing already backdoored script. ... > On ALL the machines
with the Ddos behavior we found, ... > Ddos binaries, then executing them.. ...
> This script is most likely used by CCBILL techs as part of their default ... (Incidents)