You could use the Tie::File module for this which avoids the brute approach "era" mentioned. With Tie::File you treat a file like a perl array, so if you find a pattern in a certain line you just use simple array indexing to go back one line in the file. See the Tie::File (a perl core module) documentation for usage details.
Thanks Kevin for your time and kind ..
But when I am trying to use the module Tie::File I am getting the follwing error.
This is first time I'll use a module so pls if I am doing something wrong with my code pls suggest me.
Regards,
user_prady
Last edited by user_prady; 03-31-2008 at 04:14 AM..
Hi
I'm not very good with the serach patterns and I'd need a sample how to find a line that has multiple patterns.
Say I want to find a line that has "abd", "123" and "QWERTY" and there can be any characters or numbers between the serach patterns, I have a file that has thousands of lines and... (10 Replies)
Help with script that will check log, then find a match is found, add that as the subject line.
1. The script will always run as a deamon.. and scan the event.log file
2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which... (2 Replies)
Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file.
For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt
I tried with grep -A but it's not supported on my system.
I tried with awk,... (4 Replies)
I have a file like this
DoctorName
Address1
Address2
DOB
InsuredName
Address1
Address2
DOB
PatientName
Address1
Address2
DOB
ClaimNo1
DoctorName
Address1
Address2
DOB
InsuredName (2 Replies)
Hi All,
From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able
to print text before the pattern. it display texts which is found after pattern.
awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//'
input... (4 Replies)
Hello Everyone,
I have a file with 5 fields in each line just like mentioned below. Also the 4th field is time elapsed(hh:mm:ss) since the process is running
xyz abc status 23:00:00 idle
abc def status 24:00:00 idle
def gji status 27:00:02 idle
fgh gty status 00:00:00 idle
Here I... (8 Replies)
Hi All,
totally new on it , normally use it for just 1 line.
i'm looking for help.
i'm have 2 file.
file 1 :
--------------------------------------------------
c12
c1
c3
--------------------------------------------------
file 2:
other content ... (10 Replies)
Looking for help,
i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it.
have 2 thing need do.
1st
is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018
2nd
is adding... (16 Replies)
Discussion started by: kttan
16 Replies
LEARN ABOUT DEBIAN
tie::refhash
Tie::RefHash(3perl) Perl Programmers Reference Guide Tie::RefHash(3perl)NAME
Tie::RefHash - use references as hash keys
SYNOPSIS
require 5.004;
use Tie::RefHash;
tie HASHVARIABLE, 'Tie::RefHash', LIST;
tie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;
untie HASHVARIABLE;
DESCRIPTION
This module provides the ability to use references as hash keys if you first "tie" the hash variable to this module. Normally, only the
keys of the tied hash itself are preserved as references; to use references as keys in hashes-of-hashes, use Tie::RefHash::Nestable,
included as part of Tie::RefHash.
It is implemented using the standard perl TIEHASH interface. Please see the "tie" entry in perlfunc(1) and perltie(1) for more
information.
The Nestable version works by looking for hash references being stored and converting them to tied hashes so that they too can have
references as keys. This will happen without warning whenever you store a reference to one of your own hashes in the tied hash.
EXAMPLE
use Tie::RefHash;
tie %h, 'Tie::RefHash';
$a = [];
$b = {};
$c = *main;
$d = "gunk";
$e = sub { 'foo' };
%h = ($a => 1, $b => 2, $c => 3, $d => 4, $e => 5);
$a->[0] = 'foo';
$b->{foo} = 'bar';
for (keys %h) {
print ref($_), "
";
}
tie %h, 'Tie::RefHash::Nestable';
$h{$a}->{$b} = 1;
for (keys %h, keys %{$h{$a}}) {
print ref($_), "
";
}
THREAD SUPPORT
Tie::RefHash fully supports threading using the "CLONE" method.
STORABLE SUPPORT
Storable hooks are provided for semantically correct serialization and cloning of tied refhashes.
RELIC SUPPORT
This version of Tie::RefHash seems to no longer work with 5.004. This has not been throughly investigated. Patches welcome ;-)
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself
MAINTAINER
Yuval Kogman <nothingmuch@woobling.org>
AUTHOR
Gurusamy Sarathy gsar@activestate.com
'Nestable' by Ed Avis ed@membled.com
SEE ALSO perl(1), perlfunc(1), perltie(1)perl v5.14.2 2011-09-19 Tie::RefHash(3perl)