Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find matched pattern and print all based on certain conditions Post 303039494 by RudiC on Tuesday 8th of October 2019 04:08:39 AM
Old 10-08-2019
Help me out: what does {NF--NF} do in your second awk script do? An uncommon construct, at least to me...

For your problem, how about
Code:
awk -F"\t" '
NR > 2           &&
($5-$4) > 200    &&
$3 ~ /tra_law/  {if (CNT > 3) print substr (OUT, 2)
                 SRC = $1
                 OUT = ""
                 CNT = 0
                }
$1 == SRC       {OUT = OUT ORS $0 
                 CNT ++
                }
END             {if (CNT > 3) print substr (OUT, 2)
                }

' file

lnc-1:3    OnePiece    tra_law    1    3601    1    .    .    g_id "R792.8416"# tra_law_id "R792.8416.1"# g_line "36.370155"# KM "117.008842"#
lnc-1:3    OnePiece    room       1     601    1    .    .    g_id "R792.8416"# tra_law_id "R792.8416.1"# room_number "1"# g_line "36.370155"#
lnc-1:3    OnePiece    room    1020    3001    1    .    .    g_id "R792.8416"# tra_law_id "R792.8416.1"# room_number "2"# g_line "36.370155"#
lnc-1:3    OnePiece    room    3400    3601    1    .    .    g_id "R792.8416"# tra_law_id "R792.8416.1"# room_number "3"# g_line "36.370155"#


Last edited by RudiC; 10-08-2019 at 05:17 AM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

appending with sed based on matched pattern

Hi, I want to know if you can input with sed but instead of specifing a line number like below I wan't to be able to insert based on a specific word or patttern. 10i\ Insert me after line 10 is this possible with sed or should I use AWK? Thanks Jack (2 Replies)
Discussion started by: jack1981
2 Replies

2. Shell Programming and Scripting

SED: delete and print the only exact matched pattern

I am really need help with the regular expression in SED. From input file, I need to extract lines that have the port number (sport or dport) as defined. The input file is something like this time=1209515280-1209515340 dst=192.168.133.202 src=208.70.8.23 bytes=2472 proto=6 sport=80 dport=1447... (6 Replies)
Discussion started by: new_buddy
6 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Lynx Grep Pattern Match 2 conditions Print from Start to End

I am working on a scraping project and I am stuck at this tiny grep pattern match. Sample text : FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. ABC Personal Planning Catherine K. Wat Cath Wat Catherine K. Wat Catherine K. Wat IFRAME:... (8 Replies)
Discussion started by: kkiran
8 Replies

5. Linux

Perl program to print previous set of lines once a pattern is matched

Hi all, I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in... (2 Replies)
Discussion started by: kaav06
2 Replies

6. Shell Programming and Scripting

print the whole row in awk based on matched pattern

Hi, I need some help on how to print the whole data for unmatched pattern. i have 2 different files that need to be checked and print out the unmatched patterns into a new file. My sample data as follows:- File1.txt Id Num Activity Class Type 309 1.1 ... (5 Replies)
Discussion started by: redse171
5 Replies

7. 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

8. Shell Programming and Scripting

Print line between two patterns when a certain pattern matched

Hello Friends, I need to print lines in between two string when a keyword existed in those lines (keywords like exception, error, failed, not started etc). for example, input: .. Begin Edr ab12 ac13 ad14 bc23 exception occured bd24 cd34 dd44 ee55 ff66 End Edr (2 Replies)
Discussion started by: EAGL€
2 Replies

9. 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

10. 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
MouseX::NativeTraits::Bool(3pm) 			User Contributed Perl Documentation			   MouseX::NativeTraits::Bool(3pm)

NAME
MouseX::NativeTraits::Bool - Helper trait for Bool attributes SYNOPSIS
package Room; use Mouse; has 'is_lit' => ( traits => ['Bool'], is => 'rw', isa => 'Bool', default => 0, handles => { illuminate => 'set', darken => 'unset', flip_switch => 'toggle', is_dark => 'not', }, ); my $room = Room->new(); $room->illuminate; # same as $room->is_lit(1); $room->darken; # same as $room->is_lit(0); $room->flip_switch; # same as $room->is_lit(not $room->is_lit); return $room->is_dark; # same as !$room->is_lit DESCRIPTION
This provides a simple boolean attribute, which supports most of the basic math operations. PROVIDED METHODS
These methods are implemented in MouseX::NativeTraits::MethodProvider::Bool. It is important to note that all those methods do in place modification of the value stored in the attribute. set Sets the value to true. unset Set the value to false. toggle Toggles the value. If it's true, set to false, and vice versa. not Equivalent of 'not $value'. METHODS
meta method_provider_class helper_type SEE ALSO
MouseX::NativeTraits. perl v5.14.2 2011-12-04 MouseX::NativeTraits::Bool(3pm)
All times are GMT -4. The time now is 10:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy