Sponsored Content
Top Forums Shell Programming and Scripting Perl script to match a pattern and print lines Post 302270159 by KevinADC on Friday 19th of December 2008 08:45:57 PM
Old 12-19-2008
You can use Tie::File and access the file like an array so its easy to jump lines in a file since you can use the line numbers as the array index.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Printing Multiple Lines after pattern match

Hello People, Need some assistance/guidance. OUTLINE: Two files (File1 and File2) File1 has some ids such as 009463_3922_1827 897654_8764_5432 File2 has things along the lines of: Query= 009463_3922_1827 length=252 (252 letters) More stufff here ... (5 Replies)
Discussion started by: Deep9000
5 Replies

2. Shell Programming and Scripting

sed print all lines after pattern match

HiCan someone show me how to print all lines from a file after a line matching a pattern using sed?Thanks (13 Replies)
Discussion started by: steadyonabix
13 Replies

3. Shell Programming and Scripting

print chunk of lines only if there is a pattern match in between them

Hi All, Please find the sample file below: NAME ID NUMBER -------------------------------------------------------------------------------------------------- --------- abcdefgheija;lksdf ... (13 Replies)
Discussion started by: niel.verty
13 Replies

4. Shell Programming and Scripting

print lines with exact pattern match

I have in a file domain.com. 1909 IN A 1.22.33.44 domain.com. 1909 IN A 22.33.44.55 ns1.domain.com. 1699 IN A 33.44.55.66 ns2.domain.com. 1806 IN A 77.77.66.66 I need to "grep" or "awk" out the lines starting with domain.com. as follows. domain.com. 1909 IN A 1.22.33.44 domain.com.... (3 Replies)
Discussion started by: anilcliff
3 Replies

5. Shell Programming and Scripting

perl script print the lines between two pattern

i have a file as below sample.pl parameter1 argument1 argument2 parameter2 I want out as below argument1 argument2 that is , i want to print all the lines between parameter1 & parameter 2. i tried with the following if($mystring =~ m/parameter1(.*?)parameter2/) (2 Replies)
Discussion started by: roopa
2 Replies

6. Shell Programming and Scripting

Print lines before and after pattern match

I am using Solaris, I want to print 3 lines before pattern match pattern 5 lines after pattern match Pattern is abcd to be searched in a.txt. Looking for the solution in sed/awk/perl. Thanks .. Input File a.txt: ================= 1 2 3 abcd 4 5 6 7 8 (7 Replies)
Discussion started by: manuswami
7 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. Shell Programming and Scripting

Print lines that do not match the pattern

I need to print the lines that do not match a pattern. I tried using grep -v and sed -n '/pattern/!p', but both of them are not working as I am passing the pattern as variable and it can be null some times. Example ........ abcd...... .........abcd...... .........abcd......... (4 Replies)
Discussion started by: sunny1234
4 Replies

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

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
Tie::Array(3pm) 					 Perl Programmers Reference Guide					   Tie::Array(3pm)

NAME
Tie::Array - base class for tied arrays SYNOPSIS
package Tie::NewArray; use Tie::Array; @ISA = ('Tie::Array'); # mandatory methods sub TIEARRAY { ... } sub FETCH { ... } sub FETCHSIZE { ... } sub STORE { ... } # mandatory if elements writeable sub STORESIZE { ... } # mandatory if elements can be added/deleted sub EXISTS { ... } # mandatory if exists() expected to work sub DELETE { ... } # mandatory if delete() expected to work # optional methods - for efficiency sub CLEAR { ... } sub PUSH { ... } sub POP { ... } sub SHIFT { ... } sub UNSHIFT { ... } sub SPLICE { ... } sub EXTEND { ... } sub DESTROY { ... } package Tie::NewStdArray; use Tie::Array; @ISA = ('Tie::StdArray'); # all methods provided by default package main; $object = tie @somearray,'Tie::NewArray'; $object = tie @somearray,'Tie::StdArray'; $object = tie @somearray,'Tie::NewStdArray'; DESCRIPTION
This module provides methods for array-tying classes. See perltie for a list of the functions required in order to tie an array to a package. The basic Tie::Array package provides stub "DESTROY", and "EXTEND" methods that do nothing, stub "DELETE" and "EXISTS" methods that croak() if the delete() or exists() builtins are ever called on the tied array, and implementations of "PUSH", "POP", "SHIFT", "UNSHIFT", "SPLICE" and "CLEAR" in terms of basic "FETCH", "STORE", "FETCHSIZE", "STORESIZE". The Tie::StdArray package provides efficient methods required for tied arrays which are implemented as blessed references to an "inner" perl array. It inherits from Tie::Array, and should cause tied arrays to behave exactly like standard arrays, allowing for selective overloading of methods. For developers wishing to write their own tied arrays, the required methods are briefly defined below. See the perltie section for more detailed descriptive, as well as example code: TIEARRAY classname, LIST The class method is invoked by the command "tie @array, classname". Associates an array instance with the specified class. "LIST" would represent additional arguments (along the lines of AnyDBM_File and compatriots) needed to complete the association. The method should return an object of a class which provides the methods below. STORE this, index, value Store datum value into index for the tied array associated with object this. If this makes the array larger then class's mapping of "undef" should be returned for new positions. FETCH this, index Retrieve the datum in index for the tied array associated with object this. FETCHSIZE this Returns the total number of items in the tied array associated with object this. (Equivalent to "scalar(@array)"). STORESIZE this, count Sets the total number of items in the tied array associated with object this to be count. If this makes the array larger then class's mapping of "undef" should be returned for new positions. If the array becomes smaller then entries beyond count should be deleted. EXTEND this, count Informative call that array is likely to grow to have count entries. Can be used to optimize allocation. This method need do nothing. EXISTS this, key Verify that the element at index key exists in the tied array this. The Tie::Array implementation is a stub that simply croaks. DELETE this, key Delete the element at index key from the tied array this. The Tie::Array implementation is a stub that simply croaks. CLEAR this Clear (remove, delete, ...) all values from the tied array associated with object this. DESTROY this Normal object destructor method. PUSH this, LIST Append elements of LIST to the array. POP this Remove last element of the array and return it. SHIFT this Remove the first element of the array (shifting other elements down) and return it. UNSHIFT this, LIST Insert LIST elements at the beginning of the array, moving existing elements up to make room. SPLICE this, offset, length, LIST Perform the equivalent of "splice" on the array. offset is optional and defaults to zero, negative values count back from the end of the array. length is optional and defaults to rest of the array. LIST may be empty. Returns a list of the original length elements at offset. CAVEATS
There is no support at present for tied @ISA. There is a potential conflict between magic entries needed to notice setting of @ISA, and those needed to implement 'tie'. AUTHOR
Nick Ing-Simmons <nik@tiuk.ti.com> perl v5.16.3 2013-03-04 Tie::Array(3pm)
All times are GMT -4. The time now is 02:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy