Sponsored Content
Top Forums Shell Programming and Scripting Print line between two patterns when a certain pattern matched Post 302876543 by Subbeh on Monday 25th of November 2013 09:46:42 AM
Old 11-25-2013
The code you found on the web is similar to
Code:
awk '/Pattern1/,/Pattern2/' file

If you want to print the lines only when an exception occurs, you could try something like this:
Code:
awk '/Begin Edr/{s="";p=0} {s=s $0 "\n"} /exception/{p=1} /End Edr/ && p{print s}' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print last matched pattern using perl

Hi, If there exist multiple pattern in a file, how can I find the last record matching the pattern through perl. The below script searches for the pattern everywhere in an input file. #! /usr/bin/perl -s -wnl BEGIN { $pattern or warn"Usage: $0 -pattern='RE' \n" and exit 255;... (5 Replies)
Discussion started by: er_ashu
5 Replies

2. Shell Programming and Scripting

Print only matched pattern in perl

Hi, I have script like below: #!/usr/local/bin/perl use strict; use warnings; while (<DATA>) { ( my ($s_id) = /^\d+\|(\d+?)\|/ ) ; if ( $s_id == 1 ){ s/^(.*\|)*.*ABC\.pi=(+|+)*.*ABC\.id=(\d+|+).*$/$1$2|$3/s; print "$1$2|$3\n"; (2 Replies)
Discussion started by: sol_nov
2 Replies

3. Shell Programming and Scripting

Insert certain field of matched pattern line above pattern

Hello every, I am stuck in a problem. I have file like this. I want to add the fifth field of the match pattern line above the lines starting with "# @D". The delimiter is "|" eg > # @D0.00016870300|0.05501020000|12876|12934|3||Qp||Pleistocene||"3 Qp Pleistocene"|Q # @P... (5 Replies)
Discussion started by: jyu3
5 Replies

4. Shell Programming and Scripting

Delete lines and the first pattern between 2 matched patterns

Hi, i need help to delete all the lines between 2 matched patterns and the first pattern must be deleted too. sample as follows: inputfile.txt >kump_1 ........................... ........................... >start_0124 dgfhghgfh fgfdgfh fdgfdh >kump_2 ............................. (7 Replies)
Discussion started by: redse171
7 Replies

5. Shell Programming and Scripting

Matched multiple patterns that could be in a same line

Hi, I need help to match pattern started with "RW" in file 1 and with pattern in $1 in file 2 as follows:- File 1 BH /TOTAL=466(423); /POSITIVE=300(257); /UNKNOWN=25(25); BH /F_P=141(141); /F_N=136; /P=4; CC /TAX=!?; /MAX-R=2; CC /VER=2; RW P9610, AR_BSU , T; PAE25, AE_E57... (10 Replies)
Discussion started by: redse171
10 Replies

6. Shell Programming and Scripting

Regex: print matched line and exact pattern match

Hi experts, I have a file with regexes which is used for automatic searches on several files (40+ GB). To do some postprocessing with the grep result I need the matching line as well as the match itself. I know that the latter could be achieved with grep's -o option. But I'm not aware of a... (2 Replies)
Discussion started by: stresing
2 Replies

7. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

8. UNIX for Advanced & Expert Users

To print from the first line until pattern is matched

Hi I want to print the line until pattern is matched. I am using below code: sed -n '1,/pattern / p' file It is working fine for me , but its not working for exact match. sed -n '1,/^LAC$/ p' file Input: LACC FEGHRA 0 LACC FACAF 0 LACC DARA 0 LACC TALAC 0 LAC ILACTC 0... (8 Replies)
Discussion started by: Abhisrajput
8 Replies

9. Shell Programming and Scripting

How to print two matched patterns only from each line?

My input looks like this. # Lot Of CODE Before AppType_somethinglese=$(cat << EOF AppType_test1='test-tool/blatest-tool-ear' AppType_test2='test/blabla-ear' # Lot Of CODE After I want to print text betwen 1) _ and = and 2)/ and ' from each line and exclude lines with "EOF". Output... (2 Replies)
Discussion started by: kchinnam
2 Replies

10. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies
REGEXP-ASSEMBLE(1p)					User Contributed Perl Documentation				       REGEXP-ASSEMBLE(1p)

NAME
regexp-assemble - Assemble a list of regular expressions from a file SYNOPSIS
regexp-assemble -abcdfinprsStTuUvw file [...] DESCRIPTION
Assemble a list of regular expression either from standard input or a file, using the Regexp::Assemble module. OPTIONS
-a look Ahead. Insert "(?=...)" zero-width lookahead assertions in the pattern, where necessary. -b Blank. Ignore blank lines. -c Comment. Basic comment filtering. Strip off perl/shell comments ("s*#.*$/"). -d Debug. Turns on debugging output. See Regexp::Assemble for suitable values. -i Indent. Print the regular expression using and indent of n to display nesting. A.k.a pretty-printing. Implies -p. -n No newline. Do not print a newline after the pattern. Useful when interpolating the output into a templating system or similar. -p Print. Print the pattern. This is the default, however, it is required when the -t switch is enabled (because if you want to test patterns ordinarily you don't care what the the assembled pattern looks like). -r Reduce. The default behaviour is to reduce the assembled pattern. Enabling this switch causes the reduction algorithm to be switched off. This can help you determine how much reduction is performed. regexp-assemble pattern.file | wc # versus regexp-assemble -r pattern.file | wc -s Statistics. Print some statistics about the assembled pattern. The output is sent to STDERR (in order to allow the generated pattern to be redirected elsewhere). -S Statistics only. Like -s, except that the pattern itself is not output. Useful with -d 8 to see the time taken. -t Test. Test the assembled expression against the contents of a file. Each line is read from the file and is matched against the pattern. Lines that fail to match are printed. In other words, no output is good output. In this mode of operation, error status is 1 in the case of a failure, 0 if all lines matched. -T Time. Print statistics on the time taken to reduce and assemble the pattern. (This is merely a lazy person's synonym for "-d 8"). -u Unique. Carp if duplicate patterns are found. -U Unroll. Transform "a+" et al into "aa*" (which may allow additional reductions). -v Version. Print the version of the regexp-assemble script. -w Word/Whole. When testing the contents of a file with "-t", bracket the expression with "^" and "$" in order to match the whole word or line from the file. DIAGNOSTICS
Will print out a summary of the problem if an added pattern causes the assembly to fail. SEE ALSO
Regexp::Assemble AUTHOR
Copyright (C) 2004-2008 David Landgren. All rights reserved. LICENSE
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-30 REGEXP-ASSEMBLE(1p)
All times are GMT -4. The time now is 05:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy