Sponsored Content
Top Forums Shell Programming and Scripting print next word after found pattern Post 302492161 by Scrutinizer on Sunday 30th of January 2011 06:14:09 AM
Old 01-30-2011
Try this:
Code:
awk '{for(i=1;i<=NF;i++)if($i~/pattern/)print $(i+1)}' infile

This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies

2. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

3. Shell Programming and Scripting

Print the 2nd line everytime after defined pattern is found.

Hi, I have a text file similar to the example below and I want to print the second line every time after the "--------------------------" pattern is found. The pattern is a fixed length of - characters. Example of input; 1 -------------------------- 2 3 39184018234 4 ... (10 Replies)
Discussion started by: lewk
10 Replies

4. Shell Programming and Scripting

print word after pattern match in two instances

i have a file like below. how can i printout the digits followed by the pattern -bwout and -bwin. say i run the script by entering line number 145 (the fourth line), then the o/p should be like 5000000 1024000 8 test1 -ipprot erp -ppsout 500 -ppsin 500 -bwout 300000 -bwin 300000 -statsdevice... (7 Replies)
Discussion started by: sb245
7 Replies

5. Shell Programming and Scripting

Print characters till the next space when the pattern is found

i have a file which contains alphanumeric data in every line. what i need is the data after certain pattern. the data after the pattern is not of fixed length so i need the data till the space after the pattern. Input file: bfdkasfbdfg khffkf lkdhfhdf pattern (datarequired data not required)... (2 Replies)
Discussion started by: gpk_newbie
2 Replies

6. Shell Programming and Scripting

awk to print all lines after a pattern is found

Is there a way with aw to print all lines after a string is found There is a file like this ....... ........ 2012/19/11 :11.58 PM some data lne no date 2012/19/11 :11.59 PM some other data 2012/20/11 :12.00 AM some other data some line without dates some more lines without dates... (8 Replies)
Discussion started by: swayam123
8 Replies

7. Shell Programming and Scripting

Copy/print all lines between pattern is found in .log files

Hi, I have a folder with multiple (< 33) .log files. And I have to copy the lines between two patterns from all the .log files to a new file. (script file with a loop?) Thanks in advance. 1.log ... .. xx1> begin ... .. .. >>> Total: 2 Alarms .. .. (17 Replies)
Discussion started by: AK47
17 Replies

8. Shell Programming and Scripting

Print character after pattern found

Hi Gurus, i need your help to create a script the will print a characters after the pattern was found. Sample lines are below: My birthday:"1977-16-07", My birthday:"1975-16-07" My birthday:"1970-16-07". My patter should be "birthday:", then i want to print the following characters which... (18 Replies)
Discussion started by: scripter123
18 Replies

9. Shell Programming and Scripting

How to print few lines before and after matching word is found suing grep?

Hi, here are few lines present in the logs. I want to grep on Error and print few lines before and after Error word is found line1 Line2 Line3 Error Line4 Line5 Line6 Line7 I want the output to be Line2 Line3 Error Line5 (1 Reply)
Discussion started by: arghadeep adity
1 Replies

10. Shell Programming and Scripting

Recursively grep for a pattern and print that whole word

Hello Forum Members, I am trying to write a script for a requirement where i have to recursively search for a pattern and replace it with the new string in run time from user inputs grep -ohr "]*.xyz.com]*" $HOME/source/group/ | sort | uniq > $HOME/output.txt while read -r -u9 line; ... (4 Replies)
Discussion started by: raokl
4 Replies
Regexp::Common::list(3) 				User Contributed Perl Documentation				   Regexp::Common::list(3)

NAME
Regexp::Common::list -- provide regexes for lists SYNOPSIS
use Regexp::Common qw /list/; while (<>) { /$RE{list}{-pat => 'w+'}/ and print "List of words"; /$RE{list}{-pat => $RE{num}{real}}/ and print "List of numbers"; } DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface. Do not use this module directly, but load it via Regexp::Common. $RE{list}{-pat}{-sep}{-lastsep} Returns a pattern matching a list of (at least two) substrings. If "-pat=P" is specified, it defines the pattern for each substring in the list. By default, P is "qr/.*?S/". In Regexp::Common 0.02 or earlier, the default pattern was "qr/.*?/". But that will match a single space, causing unintended parsing of "a, b, and c" as a list of four elements instead of 3 (with "-word" being "(?:and)"). One consequence is that a list of the form "a,,b" will no longer be parsed. Use the pattern "qr /.*?/" to be able to parse this, but see the previous remark. If "-sep=P" is specified, it defines the pattern P to be used as a separator between each pair of substrings in the list, except the final two. By default P is "qr/s*,s*/". If "-lastsep=P" is specified, it defines the pattern P to be used as a separator between the final two substrings in the list. By default P is the same as the pattern specified by the "-sep" flag. For example: $RE{list}{-pat=>'w+'} # match a list of word chars $RE{list}{-pat=>$RE{num}{real}} # match a list of numbers $RE{list}{-sep=>" "} # match a tab-separated list $RE{list}{-lastsep=>',s+ands+'} # match a proper English list Under "-keep": $1 captures the entire list $2 captures the last separator $RE{list}{conj}{-word=PATTERN} An alias for $RE{list}{-lastsep=>'s*,?s*PATTERNs*'} If "-word" is not specified, the default pattern is "qr/and|or/". For example: $RE{list}{conj}{-word=>'et'} # match Jean, Paul, et Satre $RE{list}{conj}{-word=>'oder'} # match Bonn, Koln oder Hamburg $RE{list}{and} An alias for $RE{list}{conj}{-word=>'and'} $RE{list}{or} An alias for $RE{list}{conj}{-word=>'or'} SEE ALSO
Regexp::Common for a general description of how to use this interface. AUTHOR
Damian Conway (damian@conway.org) MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be). BUGS AND IRRITATIONS
Bound to be plenty. For a start, there are many common regexes missing. Send them in to regexp-common@abigail.be. LICENSE and COPYRIGHT This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail. This module is free software, and maybe used under any of the following licenses: 1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT. perl v5.18.2 2013-03-08 Regexp::Common::list(3)
All times are GMT -4. The time now is 10:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy