Sponsored Content
Top Forums Shell Programming and Scripting match a pattern and print the line once Post 302333510 by bhagirathi on Monday 13th of July 2009 09:22:46 AM
Old 07-13-2009
Quote:
Originally Posted by rakeshawasthi
Your code looks familiar to me. Smilie Change the below line...
Code:
if($0 ~ "<cisco:meNm>") {S=substr($1,13,11); if(S!=prevS && S!="") {print S;S=prevS}}
and type 
prevS="" after cpt=0

I could not verify this code, so please look for { } and ()
still i am getting the same result
Code:
10.1.100.19
10.1.100.19
10.1.100.19
10.1.100.19
cpt=2
sptp=2
10.1.100.20
cpt=1
sptp=1

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

match a pattern, print it and the next line

I have a file nbu_faq.txt (Question/answer) which looks like this What I am trying to do is write out each question in a file1.txt and than the question/answer in a file2.txt like this file1.txt Q: What is nbu? Q: What is blablabla...? Q: Why ....? file2.txt Q: What is nbu? A:... (4 Replies)
Discussion started by: nymus7
4 Replies

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

3. UNIX for Dummies Questions & Answers

MATCH A PATTERN AND PRINT A LINE ABOVE AND BELOW

Dear All, Hv a very specific requirement. I have a very large text file and in which I have to match a pattern and insert a line above and below. Eg: My file cat test date1 date2 date3 date4 I need to match 'date3' and insert "Reminder1" above date3 and insert 'reminder2'... (4 Replies)
Discussion started by: gokulj
4 Replies

4. Shell Programming and Scripting

Print Line if next line Match a pattern

Hi All, Does anyone know how to print 1H1A....... in peal script print line ^1H1A....... if next line equal 5R0RECEIPT.... Thank for help:D Cat st.txt 1H1A-IN-11-5410-0009420|1010047766|dsds|1|N|IN|IN|000000|1||N|<<<line match 5R0RECEIPT| 5R0RECEIPT|... (2 Replies)
Discussion started by: kittiwas
2 Replies

5. Shell Programming and Scripting

awk print pattern match line and following lines

Data: Pattern Data Data Data Data Data Data Data Data Data ... With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
Discussion started by: dmesserly
9 Replies

6. Shell Programming and Scripting

Print only next pattern in a line after a pattern match

I have 2013-06-11 23:55:14 1Umexd-0004cm-IG <= user@domain.com I need sed/awk operation on this, so that it should print the very next pattern only after the the pattern mach <= ie only print user@domain.com (7 Replies)
Discussion started by: anil510
7 Replies

7. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

8. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 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. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies
Safe::Hole(3pm) 					User Contributed Perl Documentation					   Safe::Hole(3pm)

NAME
Safe::Hole - make a hole to the original main compartment in the Safe compartment SYNOPSIS
use Safe; use Safe::Hole; $cpt = new Safe; $hole = new Safe::Hole {}; sub test { Test->test; } $Testobj = new Test; # $cpt->share('&test'); # alternate as next line $hole->wrap(&test, $cpt, '&test'); # ${$cpt->varglob('Testobj')} = $Testobj; # alternate as next line $hole->wrap($Testobj, $cpt, '$Testobj'); $cpt->reval('test; $Testobj->test;'); print $@ if $@; package Test; sub new { bless {},shift(); } sub test { my $self = shift; $self->test2; } sub test2 { print "Test->test2 called "; } DESCRIPTION
We can call outside defined subroutines from the Safe compartment using share(), or can call methods through the object that is copied into the Safe compartment using varglob(). But that subroutines or methods are executed in the Safe compartment too, so they cannot call another subroutines that are dinamically qualified with the package name such as class methods nor can they compile code that uses opcodes that are forbidden within the compartment. Through Safe::Hole, we can execute outside defined subroutines in the original main compartment from the Safe compartment. Note that if a subroutine called through Safe::Hole::call does a Carp::croak() it will report the error as having occured within Safe::Hole. This can be avoided by including Safe::Hole::User in the @ISA for the package containing the subroutine. Methods new [NAMESPACE] Class method. Backward compatible constructor. NAMESPACE is the alternate root namespace that makes the compartment in which call() method execute the subroutine. Default of NAMESPACE means the current 'main'. This emulates the behaviour of Safe-Hole-0.08 and earlier. new \%arguments Class method. Constructor. The constructor is called with a hash reference providing the constructor arguments. The argument ROOT specifies the alternate root namespace for the object. If the ROOT argument is not specified then Safe::Hole object will attempt restore as much as it can of the environment in which it was constrtucted. This includes the opcode mask, %INC and @INC. If a root namespace is specified then it would not make sense to restore the %INC and @INC from main:: so this is not done. Also if a root namespace is given the opcode mask is not restored either. call $coderef [,@args] Object method. Call the subroutine refered by $coderef in the compartment that is specified with constructor new. @args are passed as the arguments to the called $coderef. Note that the arguments are not currently passed by reference although this may change in a future version. wrap $ref [,$cpt ,$name] Object method. If $ref is a code reference, this method returns the anonymous subroutine reference that calls $ref using call() method of Safe::Hole (see above). If $ref is a class object, this method makes a wrapper class of that object and returns a new object of the wrapper class. Through the wrapper class, all original class methods called using call() method of Safe::Hole. If $cpt as Safe object and $name as subroutine or scalar name specified, this method works like share() method of Safe. When $ref is a code reference $name must like '&subroutine'. When $ref is a object $name must like '$var'. Name $name may not be same as referent of $ref. For example: $hole->wrap(&foo, $cpt, '&bar'); $hole->wrap(sub{...}, $cpt, '&foo'); $hole->wrap($objfoo, $cpt, '$objbar'); root Object method. Return the namespace that is specified with constructor new(). If no namespace was then root() returns 'main'. Warning You MUST NOT share the Safe::Hole object with the Safe compartment. If you do it the Safe compartment is NOT safe. This module provides a means to go from a state where an opcode is denied back to a state where it is not. Reasonable care has been taken to ensure that programs cannot simply manipulate the internals to the Safe::Hole object to reduce the opmask in effect. However there may still be a way that the authors have not considered. In particular it relies on the fact that a Perl program cannot change stuff inside the magic on a Perl variable. If you install a module that allows a Perl program to fiddle inside the magic then this assuption breaks down. One would hope that any system that was running un-trusted code would not have such a module installed. AUTHORS
Sey Nakajima <nakajima@netstock.co.jp> (Initial version) Brian McCauley <nobull@cpan.org> (Maintenance) Todd Rinaldo <toddr@cpan.org> (Maintenance) SEE ALSO
Safe(3). perl v5.14.2 2011-11-15 Safe::Hole(3pm)
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy