LinuxQuestions.org
Help answer threads with 0 replies.
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, 12: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, 12:59 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,630

Rep: Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265
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, 03:15 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

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

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

All times are GMT -5. The time now is 04:35 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
Open Source Consulting | Domain Registration