LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-19-2009, 09:06 AM   #1
BillKat
LQ Newbie
 
Registered: Jan 2009
Location: UK
Distribution: Red Hat Enterprise
Posts: 15

Rep: Reputation: 0
Adding lines of text to beginning of a text file


Hi folks,

I need to insert 3-4 lines of text to the beginning of a text file. The file is a largish MYSQL dump, the result of a backup shell script. This shell script should insert the required text.

I've wrestled with sed, but lost ... Any ideas would be much appreciated, cheers.
 
Old 01-19-2009, 10:08 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
There are a lot of ways to do that. A sed command is 'i' which stats for insert a new line before the pattern. Specify only the first line as address and the trick is done:
Code:
sed -i.bak '1i text to add' file
 
Old 01-19-2009, 10:40 AM   #3
BillKat
LQ Newbie
 
Registered: Jan 2009
Location: UK
Distribution: Red Hat Enterprise
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for that, job done.
 
  


Reply

Tags
inserting, scripting, shell, text


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Add text to the beginning of file names xebix Linux - Newbie 5 10-02-2008 12:43 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
writing text to the beginning of a file linuxmandrake Linux - Newbie 3 03-26-2006 10:55 PM
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM
adding text to lines in a file tpreitano Linux - General 2 10-04-2005 09:30 AM


All times are GMT -5. The time now is 12:40 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration