Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding content to a file

Status
Not open for further replies.

minus0

Programmer
Feb 20, 2003
73
US
Greetings all,

I have a few lines that need to be added to a file, not at the end of the file but in the middle of a file after a particular line, for ex
$>echo myFile.ini
1234
3434
5434
9434


the 4 lines to be inserted into myFile.ini are

abcd
dfef
erer
qqer

now after adding the above 4 lines if I do a
$>cat myFile.ini
1234
3434
abcd
dfef
erer
qqer
5434
9434

after a particular line, say "common properties" - Is this possible, if yes, can some one please give me the directions to go about it.


Thanks for your time
-0
 
If you want to insert text after a line containing a particular string ('common properties' for example) you can do :
[tt]
sed '/common properties/ainserted line 1
inserted line 2
' myFile.ini
[/tt]
To insert the text before the line, replace 'a\' by 'i\'


If the text to be inserted is in a file (' insert.ini' for example) :
[tt]
sed '/common properties/r insert.ini' myFile.ini
[/tt]


You can also select the line by its number ('2' for example) :
[tt]
sed '2r insert.ini' myFile.ini
[/tt]

Jean Pierre.
 
Jean Pierre,

I will try this out and let you know (hope you wont mind) if I run into any problems, but thanks a bunch for the help.

-0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top