|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Print all lines before first match
Hi, I have this file. Code:
close block3c block3b block3a open close block2b block2a open close block1a open and I need : Code:
open block3a block3b block3c close I think that it could be done with sed, but does anyone can help me with that? Thanks Last edited by Franklin52; 11-30-2012 at 05:46 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Please use code tags for code and data sample. Code:
awk '/open/ && !a{a=NR}{A[NR]=$0}END{for(i=a;i>=1;i--){print A[i]}}' file |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] Print lines that match certain criteria | gautig | Shell Programming and Scripting | 2 | 03-14-2012 01:04 PM |
| Print lines before and after pattern match | manuswami | Shell Programming and Scripting | 7 | 02-01-2012 06:07 AM |
| find a word and print n lines before and after the match | chidori | Shell Programming and Scripting | 14 | 12-09-2011 02:58 PM |
| Awk print all lines on match? | MrEddy | UNIX for Dummies Questions & Answers | 9 | 04-08-2011 10:55 AM |
| how to print all lines from a second match | kchinnam | Shell Programming and Scripting | 1 | 08-11-2010 04:22 PM |
|
|