Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find matched pattern and print all based on certain conditions Post 303041540 by RudiC on Wednesday 27th of November 2019 09:52:06 AM
Old 11-27-2019
Well, looks like any tra_law line should reset the counters, regardless of the $5 - $4 delta value. Try this small adaption.



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

' file

Your new file seems to have multiple <TAB> chars as field separators?
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
match(1)							Mail Avenger 0.8.3							  match(1)

NAME
match - Match strings against glob paterns SYNOPSIS
match [-gilrqs] [-n <n>] [-c cmd] [-x code] {[-p] pattern | -f <file>} str1 [str2 ...] DESCRIPTION
match checks strings against pattern, which should be a shell-like glob pattern. pattern may contain the following special characters: ? A "?" character in pattern matches any single character in the string, except that the "/" character is only matched if match was given the -s option. * A "*" character in pattern matches zero or more characters in the string. The exception is that it will only match "/" characters if match was given the -s option. [...] A set of characters between square brackets matches any character in the set. In addition, the "-" character can be used to specify a range. For example "[+e0-3]" would match any of the characters "+", "e", 0, 1, 2, or 3 in the input string. To include a hyphen ("-") in the set of characters matched, either include the hyphen first or last, or escape it with a "". [!...] A character class preceded by a "!" matches any character but those specified in the class. The exception is that the negated character class will match a "/" only if match was given the -s option. c The backslash character escapes the next character c. Thus, to match a literal "*", you would use the pattern "*". match prints each string that matches pattern, one per line, and exits 0 if one or more strings matched. If no string matches, match exits with status 67 (or whatever alternate status was specified by the -x flag). If the -n n flag was specified, match prints only the text that matched the nth occurrence of "*" in the patten. OPTIONS -f file Specifies that the pattern should be read from file. match will read each line of the file and consider it as pattern to match against the argument strings. For each argument string, match stops when it hits the first matching line of the file. If file does not exist, match exits 67, or whatever code was specified by -x. -g Normally, the -n option selects text matching particular "*" characters in the patern. -g changes this behavior to use parentheses for grouping. Thus, for instance, the text "foo.c" would match pattern "*(.[ch])", and the output with option -n 1 would be ".c". To include a literal "(" or ")" in the pattern with the -g option, you must precede the character with a "". -i Makes the match case insensitive. str will be considered to match if any variation on its capitalization would match. For example, string "G" would match pattern "[f-h]". -l When a pattern matches the string in more than one way, the -l flag says to assign as much text as possible to the leftmost "*"s in the pattern. For example, pattern "*+*" would match text "a+b+c", and the first "*" would match "a+b". This behavior is the default, thus -l's effect is only to undo a previous -r flag. -n n With this flag, match prints the text that matched the nth "*" in the pattern, as opposed to printing the whole string. The leftmost "*" corresponds to -n 1. Specifying -n 0 causes match to print the whole matching string. Specifying -n -1 or using a value greater than the number of "*"s in the pattern causes match not to print anything, in which case you can still use the exit status to see if there is a match. The default value for n is 0, unless -g has also been specified, in which case the default is 1. -c command When -c is specified, match runs command with the system shell (/bin/sh), giving it as argument $0 the full string that matched, and as arguments $1, $2, etc., the parts of the string that matched any "*"s in pattern. If the command does not exit with status 0, match will exit immediately, before processing further matches, with whatever status command returned. The -c and -n flags are mutually exclusive. -p pattern Specifies the pattern to match against. The -p flag is optional; you can specify pattern as the first argument following the options. However, if you want to try matching the same input string against multiple patterns, then you must specify each pattern with a -p flag. -q This option is synonymous with -n -1; it suppresses output when there is a match. You can still determine whether a match occurred by the exit status. -r When a pattern matches the string in more than one way, the -r flag says to assign as much text as possible to the rightmost "*"s in the pattern. For example, with -r, pattern "*+*" would match text "a+b+c" with the "*" matching "a", and the second matching "b+c". -s Ordinarily, "*", "?", and negated character classes ("[!...]") do not match "/" characters. -s changes this behavior to match slashes. -x code By default, when there is no match, match exits with status 67. With this option, match exits with status code, instead. EXAMPLES
Suppose you have a directory with a bunch of files ending .c and .o. If, for each file named foo.c you want to attempt to delete the file foo.o, you can run the following command: match -p '*.c' -c 'rm -f $1.o' *.c Servers running the mailman list manager often send mail from bounce addresses of the form listname-bounces@host.com. If you subscribe to multiple lists on the same server, the mailman interface makes it easier if you subscribe under the same address. To split the mail into multiple folders based on the bounce address in the environment variable SENDER, you might chose a mailbox with the following shell code: name=`match -n1 "*-bounces@host.com" "$SENDER"` && echo "$HOME/Mail/incoming/host-$name.spool" SEE ALSO
avenger(1), avenger.local(8) The Mail Avenger home page: <http://www.mailavenger.org/>. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 match(1)
All times are GMT -4. The time now is 07:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy