GREP Issue in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GREP Issue in Perl
# 1  
Old 01-04-2012
Question GREP Issue in Perl

Im storing multiple functions in a varaible called $check...
The variable check contains the following:
Code:
a()
b()
c()
...
..etc

now im checking individually which function is kept in which file using GREP
Code:
if ( grep \$check \i, <FILE> )

The problem is im getting the output for the following functions also:
Code:
a(
a();
b(
b();

How to match only a()
Code:
b()
c()

etc..etc..using the grep..


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-04-2012 at 03:37 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-04-2012
Something like this?

Code:
$ cat input
a()
b()
$ cat input2
b()
$ cat input3
c()

perl code:
  1. #! /usr/bin/perl -w
  2. use strict;
  3.  
  4. my @check = qw / a() b() c() /;
  5. my @files = glob "input*";
  6. my ($fl, $fn);
  7.  
  8. for $fl (@files) {
  9.     for $fn (@check) {
  10.         open I, "< $fl";
  11.         if (grep {/$fn/} <I>) { print "$fl contains $fn\n" }
  12.         close I;
  13.     }
  14. }

Code:
$ ./test.pl
input contains a()
input contains b()
input2 contains b()
input3 contains c()

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with grep

Hello, I have an input file that looks like so: LDLR LDLRAD4 VLDLR when I grep "LDLR" I get an output of: LDLR LDLRAD4 VLDLR Since all names have "LDLR" included within them, but all I want the output to be is LDLR I know it can work if I surround the words with pipes for... (5 Replies)
Discussion started by: Rabu
5 Replies

2. UNIX for Dummies Questions & Answers

Grep issue

HI, I have a command to check a license file. License_print. In that file you get the headlines and all different licenses. Now i want to have things extracted from it. so i do like following: license_print | grep -iw -e "user" -e "admin" But i donīt want all lines where user is... (11 Replies)
Discussion started by: Tzwaj
11 Replies

3. Shell Programming and Scripting

Issue with grep

Dear All, I am using the grep command.. bash-3.2$ grep TR2 /mydata/MISE/MAPPLI/USD/mytransfer/_SRY10566_124005.mail | cut -d "/" -f2-|cut -d ":" -f2 The output is /my_repo/*/MYOPS/SR123/SRY78623/RDM/RY_USD bash-3.2$ abc=$(grep TR2 /mydata/MISE/MAPPLI/USD/mytransfer/_SRY10566_124005.mail... (1 Reply)
Discussion started by: yadavricky
1 Replies

4. Shell Programming and Scripting

Issue with grep

Hi there, I need to grep out 1 line of a changing file. Any help would be much appreciated. code: xterm -hold -e tail -f /var/lib/dhcp3/dhcpd.leases | grep client-hostname &>/dev/null & The trouble is it shows the contents of the entire lease file. I just want to show the line... (5 Replies)
Discussion started by: digitalviking
5 Replies

5. UNIX for Dummies Questions & Answers

Grep issue

more Hello.txt it was a sunny way and i was about to go home. I need to grep and redirect to a new file all the text between 'sunny' and 'go' string above. Note: There may be multiple lines in between the string i need to grep between. If there are multiple 'go' strings it should grep till... (9 Replies)
Discussion started by: mohtashims
9 Replies

6. Shell Programming and Scripting

grep issue

The below command is not working stackmem="$(pmap $1 | grep -i '' | awk '{print $2}'| tr -d ' K')" I need to grep strictly for ----> Regards, Mohtashim (2 Replies)
Discussion started by: mohtashims
2 Replies

7. Shell Programming and Scripting

Perl - grep issue in filenames with wildcards

Hi I have 2 directories t1 and t2 with some files in it. I have to see whether the files present in t1 is also there in t2 or not. Currently, both the directories contain the same files as shown below: $ABC.TXT def.txt Now, when I run the below script, it tells def.txt is found,... (5 Replies)
Discussion started by: guruprasadpr
5 Replies

8. Shell Programming and Scripting

Grep Issue

<record> <set> <termId>1234</termId> <termType>First</termType> </set> <set> <termId>5678</termId> <termType>Second</termType> </set> </record> This is saved in record.xml Hi I have this sample XML that i am grepping using a shell program. The objective of the task is - based... (7 Replies)
Discussion started by: revertback
7 Replies

9. UNIX for Dummies Questions & Answers

Issue with grep

I have a file that has the following: 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 ... (5 Replies)
Discussion started by: Pablo_beezo
5 Replies

10. UNIX for Dummies Questions & Answers

issue with grep

using grep, i have a file emp.lst, and i want all those records where "S" or "s" (capital or small) is not there i used this grep emp.lst when i use grep emp.lst i am getting rows with S..but why negate (^) is not working? (3 Replies)
Discussion started by: soujanya_srk
3 Replies
Login or Register to Ask a Question