LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-09-2013, 01:49 AM   #1
gushnik1
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Rep: Reputation: Disabled
sed multiple lines previous line


Hi every body,

I know the sed command with N character for append the next line.

There is a way to do the opposite action?

I want to get the previous line..

Thanks.
 
Old 10-09-2013, 01:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,612

Rep: Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365Reputation: 4365
can you please give us an example or more details? Sed has a "hold space" you can use it to store the previous line.
 
Old 10-09-2013, 04:15 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394Reputation: 2394
Quote:
Originally Posted by gushnik1 View Post
Hi every body,

I know the sed command with N character for append the next line.

There is a way to do the opposite action?

I want to get the previous line..

Thanks.
Maybe this will help:
Code:
$ cat infile
foo
bar
previous line 1
current line
foobar
fubar
previous line 2
current line

$ sed -rn 'N;/current line/{s/(.*)\n.*/\1/p}' infile 
previous line 1
previous line 2
 
  


Reply


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
Remove lines based upon the previous line Adzrules Linux - Newbie 2 11-16-2012 07:18 AM
sed works on multiple lines but doesn't work on a single line monsteriname Programming 4 10-03-2012 03:23 AM
Search multiple lines in sed or vi vijay_babu1981 Linux - Newbie 8 10-30-2009 12:02 PM
SED multiple lines masterdam79 Linux - Newbie 6 10-29-2009 05:25 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 06:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration