Perl search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl search
# 1  
Old 12-02-2009
Perl search

the log reads as follows:

Code:
input()
0 UNIQ_ID 012
0 NAME SQL
0 TIME 01/12/2009 10.10.00
0 CODE PIN_ACTIVATE_CHECK1
output()
0 CHECKED
1 ENABLED
input()
0 UNIQ_ID 013
0 NAME SQL
0 TIME 01/12/2009 12.10.00
0 CODE PIN_ACTIVATE_CHECK2
output()
0 CHECKED
1 ENABLED

i want to search for the string PIN_ACTIVATE and based on that the field(CODE), corresponding input() and output() have to be displayed.
Kindly help me in writing a perl script for this.

Last edited by radoulov; 12-02-2009 at 05:49 AM.. Reason: Use code tags, please!
# 2  
Old 12-02-2009
Please post an example of the desired output.
# 3  
Old 12-02-2009
Code:
input()
0 UNIQ_ID 012
0 NAME SQL
0 TIME 01/12/2009 10.10.00
0 CODE PIN_ACTIVATE_CHECK1

output() is -->
Code:
0 CHECKED
1 ENABLED

CODE --> PIN_ACTIVATE_CHECK2
Code:
input()
0 UNIQ_ID 013
0 NAME SQL
0 TIME 01/12/2009 12.10.00
0 CODE PIN_ACTIVATE_CHECK2

output() is -->
Code:
0 CHECKED
1 ENABLED


Last edited by radoulov; 12-02-2009 at 06:14 AM.. Reason: Added code tags.
# 4  
Old 12-02-2009
So you want only the lines after the string output() after the string PIN_ACTIVATE?

Given your input:

Code:
input()
0 UNIQ_ID 012
0 NAME SQL
0 TIME 01/12/2009 10.10.00
0 CODE PIN_ACTIVATE_CHECK1
output()
0 CHECKED
1 ENABLED
input()
0 UNIQ_ID 013
0 NAME SQL
0 TIME 01/12/2009 12.10.00
0 CODE PIN_ACTIVATE_CHECK2
output()
0 CHECKED
1 ENABLED

The output should be:

Code:
0 CHECKED
1 ENABLED
0 CHECKED
1 ENABLED

Or I'm missing something?
# 5  
Old 12-02-2009
correct. it should be with the function name.
it should look like

output()
0 CHECKED
1 ENABLED
# 6  
Old 12-02-2009
Code:
perl -nle'
  /PIN_ACTIVATE|^input\(\)/ or print 
    if /PIN_ACTIVATE/../^input\(\)/
  ' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and replace (perl)

How can I achieve this? Perl would be awesome. Input string a_b c //Note there is a blank here Needed Output a_b_c Thanks (4 Replies)
Discussion started by: dragonpoint
4 Replies

2. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

3. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

4. Shell Programming and Scripting

File search in perl

Hi Gurus, Lately I have started to learn perl and need your kind support on the below query I want to search a file with name like ff_GRD_abcd_251.dat Now I will take input from user only the number i.e. 251 and the script will show o/p as the file name In the directory there are... (1 Reply)
Discussion started by: Pratik4891
1 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Shell Programming and Scripting

Search and Replace in Perl

I am trying to write a simple perl script to run on a FreeBSD machine. There are alot of posts here, and I have read so many, yet can not get this script to run. #!/usr/bin/perl -e 's/\r\n/~/' infile.txt outfile.txt I am trying to take a windows text file, move it into Unix, run a script on... (1 Reply)
Discussion started by: mach1
1 Replies

7. Shell Programming and Scripting

perl pattern search

can someone help me out with the bolded? else if (regmatch($Subject, "^Application") && (regmatch($From, "^etgh") && (regmatch($Body, ".*not authorized to use this server.*")))) what this section of the code is suppose to do is to scan through the contents of $Body, if do a set of... (1 Reply)
Discussion started by: SkySmart
1 Replies

8. Shell Programming and Scripting

Perl to Search through next lines

I have log file that I need to extract time difference occurance when two events happend, between first occurance of TV and when W_NO happend. also read the value=, below example...I can only read the next line but not able to seach all the next lines untill i see W_NO.. Thanks for your help.... (6 Replies)
Discussion started by: bataf
6 Replies

9. Shell Programming and Scripting

Perl: Search and print help

Hi all, I need a bit of help with a perl script, I have a file containing lines that look like: M1 (Agnd Agnd ibias_gnP Agnd) nch l=250.0n w=10u m=1 ad=2.5e-12 \ as=2.5e-12 pd=20.5u ps=20.5u nrd=0.025 nrs=0.025 sa=2.5e-07 \ sb=2.5e-07 M21 (Agnd VSSabc Agnd Agnd) nch... (3 Replies)
Discussion started by: Crypto
3 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question