Add Multiple Lines in an existing file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Add Multiple Lines in an existing file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-04-2006
hkhan12 hkhan12 is offline
Registered User
 
Join Date: Jan 2005
Last Activity: 2 October 2007, 4:04 AM EDT
Location: Canada
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Add Multiple Lines in an existing file

Hi Unix Experts,

I like to add the following multiple lines in an existing file:

CHANNELS:
MaxChannels=600
MaxActiveChannels=600
MaxInitiators=22

I would be highly appreciated if somebody can shed some light on it.

Thank you in advance!!!


Khan
Sponsored Links
    #2  
Old 09-05-2006
Balkrishna Balkrishna is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 5 March 2010, 1:07 AM EST
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Use VI editor to do so. Open the existing file in vi editor and then press the key escape + i. copy those lines and pest it in the required location.
Sponsored Links
    #3  
Old 09-05-2006
hkhan12 hkhan12 is offline
Registered User
 
Join Date: Jan 2005
Last Activity: 2 October 2007, 4:04 AM EDT
Location: Canada
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Balkrishna
Use VI editor to do so. Open the existing file in vi editor and then press the key escape + i. copy those lines and pest it in the required location.
Thank you for your simple solution but probably I missed in my question. Let me put it this way, How can I add multiple lines in an existing file using a script. NOT MANUALLY!!!

I hope you understand my question.

Thank you for all who can shed some light!!!

Khan
    #4  
Old 09-05-2006
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 24 October 2014, 9:49 AM EDT
Posts: 2,662
Thanks: 0
Thanked 17 Times in 17 Posts
Quote:
Originally Posted by hkhan12
Hi Unix Experts,

I like to add the following multiple lines in an existing file:

CHANNELS:
MaxChannels=600
MaxActiveChannels=600
MaxInitiators=22

I would be highly appreciated if somebody can shed some light on it.

Thank you in advance!!!


Khan
Have you any experience in shell scripting?
Anyway, to add those lines to files, you can use cat and the >>

cat existing_file >> some_file

provided your existing_file contains only the lines you want to add.
Sponsored Links
    #5  
Old 09-06-2006
haiudhaya haiudhaya is offline
Registered User
 
Join Date: Jun 2002
Last Activity: 18 October 2006, 11:57 AM EDT
Location: India (Chennai)
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
echo "MaxChannels=600
MaxActiveChannels=600
MaxInitiators=22" >> file_name

Just give your file name after redirection operator.
Sponsored Links
    #6  
Old 09-08-2006
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 8 October 2014, 1:35 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts
If you want to add those lines in any part of file then u can do that by using SED

"sedscript" file
############
/pattern/a\
CHANNELS:\
MaxChannels=600\
MaxActiveChannels=600\
MaxInitiators=22
############

sed -f sedscript ipfile

If you want to insert after for example 10th line then use
10a\

If you want to insert before that pattern or some line then use
10i\
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
Appending lines from an existing list to each line in another existing list TAPE UNIX for Dummies Questions & Answers 4 09-10-2011 04:27 PM
grep command to find multiple strings in multiple lines in a file. ritikaSharma UNIX for Dummies Questions & Answers 2 12-17-2010 03:43 AM
how to insert text between lines of an existing file using perl madhul2002 Shell Programming and Scripting 3 01-19-2009 02:08 AM
folder existing and file existing crowman Shell Programming and Scripting 4 08-28-2008 06:07 PM
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 03:28 PM



All times are GMT -4. The time now is 01:34 AM.