Sponsored Content
Top Forums Shell Programming and Scripting Pattern Match & Extract from a string Post 302760731 by Yoda on Thursday 24th of January 2013 01:55:22 PM
Old 01-24-2013
Here is one way of doing it:
Code:
while read p
do
    awk -F\| -v P="$p" '{if(match($2,P)>0) print $1,substr($2,RSTART,RLENGTH); }' OFS=\| filename
done < Patterns.txt

This User Gave Thanks to Yoda For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED: match pattern & delete matched lines

Hi all, I have the following data in a file x.csv: > ,this is some text here > ,,,,,,,,,,,,,,,,2006/11/16,0.23 > ,,,,,,,,,,,,,,,,2006/12/16,0.88 < ,,,,,,,,,,,,,,,,this shouldnt be deleted I need to use SED to match anything with a > in the line and delete that line, can someone help... (7 Replies)
Discussion started by: not4google
7 Replies

2. UNIX for Advanced & Expert Users

how can awk match multi pattern in a string

Hi all, I need to category the processes in my system with awk. And for now, there are several command with similar name, so i have to match more than one pattern to pick it out. for instance: binrundb the string1, 2 & 3 may contain word, number, blank or "/". The "bin" should be ahead "rundb"... (5 Replies)
Discussion started by: sleepy_11
5 Replies

3. Shell Programming and Scripting

pattern match url in string / PERL

Am trying to remove urls from text strings in PERL. I have the following but it does not seem to work: $remarks =~ s/www\.\s+\.com//gi; In English, I want to look for www. then I want to delete the www. and everything after it until I hit a space (but not including the space). It's not... (2 Replies)
Discussion started by: mrealty
2 Replies

4. Shell Programming and Scripting

Match pattern and replace with string

hi guys, insert into /*<new>*/abc_db.tbl_name this is should be replaced to insert into /*<new>*/${new}.tbl_name it should use '.' as delimiter and replace is there any way to do it using sed (6 Replies)
Discussion started by: sol_nov
6 Replies

5. Shell Programming and Scripting

Match first pattern first then extract second pattern match

My input file: <accession>Q91G55</accession> <name>043L_IIV6</name> <protein> <recommendedName> <location> <position position="294"/> </location> <fullName>Uncharacterized protein 043L</fullName> <accession>P18556</accession> <name>1106L_ASFB7</name> <protein> <recommendedName>... (5 Replies)
Discussion started by: patrick87
5 Replies

6. Shell Programming and Scripting

Extract data from records that match pattern

Hi Guys, I have a file as follows: a b c 1 2 3 4 pp gg gh hh 1 2 fm 3 4 g h i j k l m 1 2 3 4 d e f g h j i k l 1 2 3 f 3 4 r t y u i o p d p re 1 2 3 f 4 t y w e q w r a s p a 1 2 3 4 I am trying to extract all the 2's from each row. 2 is just an example... (6 Replies)
Discussion started by: npatwardhan
6 Replies

7. Shell Programming and Scripting

Match a Pattern & Replace The value Using AWK

I have a csv file in which i have to search a particular string and replace the data in any column with something else. How do i do it using awk. file ------ 2001,John,USA,MN,20101001,29091.50,M,Active,Y 2002,Mike,USA,NY,20090130,342.00,M,Pending,N... (3 Replies)
Discussion started by: Sheel
3 Replies

8. Shell Programming and Scripting

pattern match in a string

Hello, Please see below line code: #!/bin/ksh set -x /usr/bin/cat /home/temp |while read line do if ] then echo "matched" else echo "nope" fi done content of filr temp is as below (4 Replies)
Discussion started by: skhichi
4 Replies

9. Shell Programming and Scripting

Extract lines that match a pattern

Hi all, I got a file that contains the following content, Actually it is a part of the file content, Installing XYZ XYZA Image, API 18, revision 2 Unzipping XYZ XYZA Image, API 18, revision 2 (1%) Unzipping XYZ XYZA Image, API 18, revision 2 (96%) Unzipping XYZ XYZA Image, API 18,... (7 Replies)
Discussion started by: Kashyap
7 Replies

10. UNIX for Beginners Questions & Answers

Help with pattern match and Extract

Hi All, I am having a file like below . Basically when SB comes in the text with B. I have to take the word till SB. When there only B I should take take till B. Tried for cut it by demilter but not able to build the logic SB- CD B_RESTO SB_RESTO CRYSTALS BOILERS -->There SB and B so I... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies
Mojolicious::Routes::Pattern(3pm)			User Contributed Perl Documentation			 Mojolicious::Routes::Pattern(3pm)

NAME
Mojolicious::Routes::Pattern - Routes pattern engine SYNOPSIS
use Mojolicious::Routes::Pattern; # Create pattern my $pattern = Mojolicious::Routes::Pattern->new('/test/:name'); # Match routes my $result = $pattern->match('/test/sebastian'); say $result->{name}; DESCRIPTION
Mojolicious::Routes::Pattern is the core of Mojolicious::Routes. ATTRIBUTES
Mojolicious::Routes::Pattern implements the following attributes. "defaults" my $defaults = $pattern->defaults; $pattern = $pattern->defaults({foo => 'bar'}); Default parameters. "format" my $regex = $pattern->format; $pattern = $pattern->format($regex); Compiled regex for format matching. "pattern" my $pattern = $pattern->pattern; $pattern = $pattern->pattern('/(foo)/(bar)'); Raw unparsed pattern. "quote_end" my $quote = $pattern->quote_end; $pattern = $pattern->quote_end(']'); Character indicating the end of a quoted placeholder, defaults to ")". "quote_start" my $quote = $pattern->quote_start; $pattern = $pattern->quote_start('['); Character indicating the start of a quoted placeholder, defaults to "(". "regex" my $regex = $pattern->regex; $pattern = $pattern->regex($regex); Pattern in compiled regex form. "relaxed_start" my $relaxed = $pattern->relaxed_start; $pattern = $pattern->relaxed_start('*'); Character indicating a relaxed placeholder, defaults to "#". "reqs" my $reqs = $pattern->reqs; $pattern = $pattern->reqs({foo => qr/w+/}); Regex constraints. "symbol_start" my $symbol = $pattern->symbol_start; $pattern = $pattern->symbol_start(':'); Character indicating a placeholder, defaults to ":". "symbols" my $symbols = $pattern->symbols; $pattern = $pattern->symbols(['foo', 'bar']); Placeholder names. "tree" my $tree = $pattern->tree; $pattern = $pattern->tree([ ... ]); Pattern in parsed form. "wildcard_start" my $wildcard = $pattern->wildcard_start; $pattern = $pattern->wildcard_start('*'); Character indicating the start of a wildcard placeholder, defaults to "*". METHODS
Mojolicious::Routes::Pattern inherits all methods from Mojo::Base and implements the following ones. "new" my $pattern = Mojolicious::Routes::Pattern->new('/:action'); my $pattern = Mojolicious::Routes::Pattern->new('/:action', action => qr/w+/); my $pattern = Mojolicious::Routes::Pattern->new(format => 0); Construct a new pattern object. "match" my $result = $pattern->match('/foo/bar'); my $result = $pattern->match('/foo/bar', 1); Match pattern against entire path, format detection is disabled by default. "parse" $pattern = $pattern->parse('/:action'); $pattern = $pattern->parse('/:action', action => qr/w+/); $pattern = $pattern->parse(format => 0); Parse a raw pattern. "render" my $path = $pattern->render({action => 'foo'}); my $path = $pattern->render({action => 'foo'}, 1); Render pattern into a path with parameters, format rendering is disabled by default. "shape_match" my $result = $pattern->shape_match($path); my $result = $pattern->shape_match($path, 1); Match pattern against path and remove matching parts, format detection is disabled by default. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojolicious::Routes::Pattern(3pm)
All times are GMT -4. The time now is 11:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy