Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-31-2006
Registered User
 
Join Date: Nov 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Insert text file at a certain line.

I need to insert a file called temp_impact (which has about 15 lines in it) to a file called 11.23cfg starting at line 33. I searched the forums and found the

sed '34i\
test' 11.23cfg > newfile

That will enter word test at the appropriate line, but i need the entire file dumped there. Any help would be appreciated. This is on an HP system so no bash shell is avalible, just sh. Is there anyway to do this with sed or is there a better way to insert it all together.

Sean
Sponsored Links
    #2  
Old 07-31-2006
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,654
Thanks: 164
Thanked 645 Times in 622 Posts
open the file you want to move things into with vi.

Move the cursor down to line 15
Press colon r filename
eg.:

Code:
:r filename.txt

Press return.

The lines from filename.txt will be read and inserted in between the old lines 15 & 16
of the file you first opened with vi
Sponsored Links
    #3  
Old 07-31-2006
Registered User
 
Join Date: Nov 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
I am sorry I forgot to add this is suppose to be automated in a script, is there a way to open vi and have it insert with that command at line 35 and close with no user intervention?
    #4  
Old 07-31-2006
Registered User
 
Join Date: Jul 2006
Location: Denmark
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
I wrote a script which does just that:
http://comp.eonworks.com/scripts/insertext
Sponsored Links
    #5  
Old 08-01-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 60 Times in 56 Posts
Try something like this:

Code:
sed '33r temp_impact' <11.23cfg >11.23cfg.tmp
mv 11.23cfg.tmp 11.23cfg

Jean-Pierre.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using sed to insert text file at first line psve Shell Programming and Scripting 18 03-29-2011 03:44 AM
Sed insert text at first line of empty file DC Slick Shell Programming and Scripting 4 02-18-2011 02:17 AM
How to insert some constant text at beginig of each line within a text file. Muhammad Afzal Shell Programming and Scripting 4 10-30-2008 11:01 PM
Insert a line in a text file 4scriptmoni Shell Programming and Scripting 10 08-04-2008 10:17 AM
how to insert a extra line in a text file bhaviknp Shell Programming and Scripting 2 03-07-2008 07:38 AM



All times are GMT -4. The time now is 08:48 PM.