LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   sed multiple lines previous line (https://www.linuxquestions.org/questions/linux-software-2/sed-multiple-lines-previous-line-4175480119/)

gushnik1 10-09-2013 12:49 AM

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.

pan64 10-09-2013 12:59 AM

can you please give us an example or more details? Sed has a "hold space" you can use it to store the previous line.

druuna 10-09-2013 03:15 AM

Quote:

Originally Posted by gushnik1 (Post 5042590)
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



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