RE: Inserting Text In Specific Location Using Shell Script
- From: "Michael Velez" <mikev777@xxxxxxxxxxx>
- Date: Fri, 26 May 2006 16:10:08 -0400
-----Original Message-----
From: redhat-list-bounces@xxxxxxxxxx
[mailto:redhat-list-bounces@xxxxxxxxxx] On Behalf Of Cesar Covarrubias
Sent: Friday, May 26, 2006 3:51 PM
To: General Red Hat Linux discussion list
Subject: Inserting Text In Specific Location Using Shell Script
Hello,
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?
--
Very Respectfully,
Cesar Covarrubias
cesar@xxxxxxx
You can do this with sed. The trick is to use the 's' command in sed and
actually add a real newline in the substitution field. But the newline
needs to be preceded by a '\'. The script then contains two lines.
Here is a sample sed script which will add a line '#Addendum to comment 2'
right below '#comment 2':
s/#comment 2/#comment 2\
#Addendum to comment 2/
The output of this script executed on the example you gave us is:
#comment 1
#comment 2
#Addendum to Comment2
#comment 3
Hope this helps,
Michael
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
- Follow-Ups:
- RE: Inserting Text In Specific Location Using Shell Script
- From: Cesar Covarrubias
- RE: Inserting Text In Specific Location Using Shell Script
- 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: Re: Inserting Text In Specific Location Using Shell Script
- 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
... Cesar Covarrubias ... Inserting Text In Specific Location Using Shell
Script ... #Addendum to comment 2/ ... (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) - Re: Win2000 Pro will not process logon script
... newer machines run the script and some of the older ones do not. ...
I am not familar with the "slow link" policy. ... (microsoft.public.windows.server.active_directory)