Re: Inserting Text In Specific Location Using Shell Script
- From: Nate Mayotte <nmayotte@xxxxxxxxxxx>
- Date: Fri, 26 May 2006 13:10:36 -0700
Well, there are two ways that come to my mind to do this.
First is to use sed (or awk) to cut the first X number of lines up to and including comment 2 and save as like file1_head.txt and cut the bottem lines after comment 2 and save that as file1_tail.txt. You could even use 'head' and 'tail' for this if you know the specific line number. Then you can just do cat file_to_add_in_middle.txt >> file1_head.txt and then cat file1_tail.txt >> file1_head.txt and then mv file1_head.txt file1.txt That seems kind of backwards but it should work
The other way you could do this is using tr. This is knid of dumb but you could to tr "#comment 2" "#comment 2 these lines are the new ones" and it will add that. Although that wil probably mess up the formatting, you might be able to use like /n or something in tr to say you want a new line. good luck
Nate Mayotte
---- Cesar Covarrubias <cesar@xxxxxxx> wrote:
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
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
- 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
- Index(es):
Relevant Pages
- Re: Inserting Text In Specific Location Using Shell Script
... Cesar Covarrubias wrote: ... I am running a script on about 30 machines
and need to insert text after ... Some prerequisites: ... (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: Troubleshooting connection loss (continued)
... suggestions as to what config files are to look like" ... tip on how to follow
a complex script gone to waste on the OP. ... Instead of reading the whole document, this
is the section I have in mind. ... then do the service network start. ...
(comp.os.linux.networking)