Sponsored Content
Top Forums Shell Programming and Scripting Want to grep for a pattern and display the content above that pattern Post 302432429 by pseudocoder on Friday 25th of June 2010 03:21:19 AM
Old 06-25-2010
Code:
$ perl -nle 'if (!/FAIL/) { push @x, $_; }
             else { push @x, $_; for ( $#x-50 .. $#x ) { print $x[$_] } @x=(); }' infile

Edit: This ^^ will misbehave if there are less than 50 lines before the pattern FAIL, here's the fix:
Code:
$ perl -nle 'if (!/FAIL/) { push @x, $_; }
else { push @x, $_;
if ($#x > 50) {
for ( $#x-50 .. $#x ) { print $x[$_] } @x=(); }
else { for ( 0 .. $#x ) { print $x[$_] }} @x=(); }' infile


Last edited by pseudocoder; 06-25-2010 at 04:36 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

display content between all similar tags pattern

hi, I m stuck at a point for more than 3days. My doubt is pretty simple.. I have a web page content in $content. ( got this by using LWP).. Now I want to display the content matching a pattern. I tried if($content =~ m{<div class="abc">(.*?)</div>}s){ print $1;} that will... (4 Replies)
Discussion started by: therockravi
4 Replies

2. Shell Programming and Scripting

Grep pattern from different file and display if it exists in the required file

Hi, I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which contains rubbish information just to fill the page which is of no use. this is... (3 Replies)
Discussion started by: abinash
3 Replies

3. Shell Programming and Scripting

Grep a pattern given in one file at other file and display its corresponding contents as output.

***************************************** Right now i have this current system. I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which... (7 Replies)
Discussion started by: abinash
7 Replies

4. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

5. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

6. Shell Programming and Scripting

Grep pattern and display all lines below

Hi I need to grep for a patter and display all lines below the pattern. For ex: say my file has the below lines file1 file2 file3 file4 file5 I NEED to grep for patter file3 and display all lines below the pattern. do we have an option to get this data. Let me know if you require... (5 Replies)
Discussion started by: venkidhadha
5 Replies

7. Shell Programming and Scripting

Grep lines before a pattern having some other pattern

Hi All, I am trying to fetch lines before a pattern, I got to know about -B flag in grep but we have to pass the number to get those lines before some pattern say (X), now what if I want to get line/s with some other pattern say (Y) before X pattern? How to get about it? please help. Input:... (5 Replies)
Discussion started by: dips_ag
5 Replies

8. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

9. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

10. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies
Net::DNS::Update(3)					User Contributed Perl Documentation				       Net::DNS::Update(3)

NAME
Net::DNS::Update - Create a DNS update packet SYNOPSIS
"use Net::DNS::Update;" DESCRIPTION
"Net::DNS::Update" is a front-end for creating "Net::DNS::Packet" objects to be used for making DNS dynamic updates. Programmers should refer to RFC 2136 for the semantics of dynamic updates. WARNING: This code is still under development. Please use with caution on production nameservers. METHODS
new $packet = Net::DNS::Update->new; $packet = Net::DNS::Update->new("example.com"); $packet = Net::DNS::Update->new("example.com", "HS"); Returns a "Net::DNS::Packet" object suitable for performing a DNS dynamic update. Specifically, it creates a packet with the header opcode set to UPDATE and the zone record type to SOA (per RFC 2136, Section 2.3). Programs must use the "push" method to add RRs to the prerequisite, update, and additional sections before performing the update. Arguments are the zone name and the class. If the zone is omitted, the default domain will be taken from the resolver configuration. If the class is omitted, it defaults to IN. Future versions of "Net::DNS" may provide a simpler interface for making dynamic updates. EXAMPLES
The first example below shows a complete program; subsequent examples show only the creation of the update packet. Add a new host #!/usr/bin/perl -w use Net::DNS; use strict; # Create the update packet. my $update = Net::DNS::Update->new("example.com"); # Prerequisite is that no A records exist for the name. $update->push("pre", nxrrset("foo.example.com. A")); # Add two A records for the name. $update->push("update", rr_add("foo.example.com. 86400 A 192.168.1.2")); $update->push("update", rr_add("foo.example.com. 86400 A 172.16.3.4")); # Send the update to the zone's primary master. my $res = Net::DNS::Resolver->new; $res->nameservers("primary-master.example.com"); my $reply = $res->send($update); # Did it work? if (defined $reply) { if ($reply->header->rcode eq "NOERROR") { print "Update succeeded "; } else { print "Update failed: ", $reply->header->rcode, " "; } } else { print "Update failed: ", $res->errorstring, " "; } Add an MX record for a name that already exists my $update = Net::DNS::Update->new("example.com"); $update->push("pre", yxdomain("example.com")); $update->push("update", rr_add("example.com MX 10 mailhost.example.com")); Add a TXT record for a name that doesn't exist my $update = Net::DNS::Update->new("example.com"); $update->push("pre", nxdomain("info.example.com")); $update->push("update", rr_add("info.example.com TXT 'yabba dabba doo'")); Delete all A records for a name my $update = Net::DNS::Update->new("example.com"); $update->push("pre", yxrrset("foo.example.com A")); $update->push("update", rr_del("foo.example.com A")); Delete all RRs for a name my $update = Net::DNS::Update->new("example.com"); $update->push("pre", yxdomain("byebye.example.com")); $update->push("update", rr_del("byebye.example.com")); Perform a signed update my $key_name = "tsig-key"; my $key = "awwLOtRfpGE+rRKF2+DEiw=="; my $update = Net::DNS::Update->new("example.com"); $update->push("update", rr_add("foo.example.com A 10.1.2.3")); $update->push("update", rr_add("bar.example.com A 10.4.5.6")); $update->sign_tsig($key_name, $key); Another way to perform a signed update my $key_name = "tsig-key"; my $key = "awwLOtRfpGE+rRKF2+DEiw=="; my $update = Net::DNS::Update->new("example.com"); $update->push("update", rr_add("foo.example.com A 10.1.2.3")); $update->push("update", rr_add("bar.example.com A 10.4.5.6")); $update->push("additional", Net::DNS::RR->new("$key_name TSIG $key")); Perform a signed update with a customized TSIG record my $key_name = "tsig-key"; my $key = "awwLOtRfpGE+rRKF2+DEiw=="; my $tsig = Net::DNS::RR->new("$key_name TSIG $key"); $tsig->fudge(60); my $update = Net::DNS::Update->new("example.com"); $update->push("update", rr_add("foo.example.com A 10.1.2.3")); $update->push("update", rr_add("bar.example.com A 10.4.5.6")); $update->push("additional", $tsig); BUGS
This code is still under development. Please use with caution on production nameservers. COPYRIGHT
Copyright (c) 1997-2002 Michael Fuhr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Header, Net::DNS::Packet, Net::DNS::Question, Net::DNS::RR, RFC 2136, RFC 2845 perl v5.8.0 2002-05-30 Net::DNS::Update(3)
All times are GMT -4. The time now is 03:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy