Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-02-2010, 03:44 PM   #1
LQ Newbie
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
hot to al line before last 2 lines

I need to add a line in a file before the last two lines using a script using standard linux editors like sed but i can't figure it out.
Any suggestions?
Thank you!
Old 08-02-2010, 04:39 PM   #2
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,930
Blog Entries: 45

Rep: Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160Reputation: 3160

Welcome to LQ!

So you've shown us your need! What's your deed?

We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist.

'How to Ask Questions the Smart Way' would be one link you should look at to help us to help you in the future.

Smells like homework?

Just a few more links to aid you;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
Getting Started with Linux
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking
Virtualiation- Top 10

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
Old 08-04-2010, 12:08 AM   #3
LQ Newbie
Registered: Aug 2010
Posts: 4

Original Poster
Rep: Reputation: 0
how to add line before last 2 lines

It's a script that ads a line at a specific line number
This file is changed almost every day except the last 2 lines.
I need a way to add a line always before the last two lines
This is my script...But this one ads a new line at linenumber 400.

read a b c
sed -i "400i\ 2 rate $a$k src $b # $c" eth0.cfg
sed -i "400i\ 2 rate $a$k dst $b # $c" eth1.cfg



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
GREP: how to specify a line or lines where to search carolflb Linux - Newbie 7 11-23-2009 08:45 AM
How to grep lines containing a certain string PLUS the line following that line? kmkocot Linux - Newbie 5 09-01-2009 03:54 PM
Announcing Artha ~ An off-line English thesaurus with hot key look up & notifications legends2k Linux - News 0 02-16-2009 04:46 AM
Replace line in file with two lines?! Possible? eur0dad Linux - General 2 09-07-2006 02:15 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:25 PM.

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