LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2010, 02:41 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 49
Append a block of text into a particular section of a file?


So I have file which looks something like this:

cat .opera/operaprefs.ini

Code:
[User Prefs]
Language Files Directory=
Preferences Version=2
Has Restored MIME Flag=1
Trust Server Types=0
Enable Usage Statistics=0
Address Search Drop Down Width=180
DevTools Splitter Position=500
History View Style=0

[Extensions]
Plugin Failed Warning=1

[Security Prefs]
Enable SSL v3=1
Enable TLS v1.0=1
Enable TLS v1.1=1
Enable TLS v1.2=1
and I would like it to make it look this (see text in red color):

Code:
[User Prefs]
Language Files Directory=
Preferences Version=2
Has Restored MIME Flag=1
Trust Server Types=0
Enable Usage Statistics=0
Address Search Drop Down Width=180
DevTools Splitter Position=500
History View Style=0
Home URL=http://www.example.com
Ignore Target=0
Target Destination=0
Ignore Unrequested Popups=1

[Extensions]
Plugin Failed Warning=1

[Security Prefs]
Enable SSL v3=1
Enable TLS v1.0=1
Enable TLS v1.1=1
Enable TLS v1.2=1
i.e. basically append the text in red color. So what is the best way to do this? sed, awk I suppose.

All I am trying to is to set the Home Page of the opera through script/command line.

Thanks
 
Old 03-16-2010, 02:58 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
SED has the append and insert commands (a and i)

http://www.grymoire.com/Unix/Sed.html#uh-39

Or read in from a file using r:

http://www.grymoire.com/Unix/Sed.html#uh-37
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pipe output to append to a text file davee Linux - Newbie 5 03-22-2016 07:44 PM
append text to file cyberrate Linux - Software 3 12-02-2009 07:25 AM
want to prepend to a text file, not append urentity Programming 7 08-03-2009 12:45 AM
How can I append text to a string in a file HGeneAnthony Linux - Newbie 4 03-01-2007 12:16 PM
quickly append text to file blackzone Linux - General 3 09-07-2006 05:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration