473,413 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

unix grep to perl

hello everyone,


i have the following values : 98000345 and i would like to search this value in all of the sql files in the directory /temp/*sql

normally on unix its grep( ' 98000345 ' ,/temp/*sql)

however in perl the grep is used somehow in a different way : grep(EXPR,ARRAY/LIST)

could anyone suggest how do i implement...grep( ' 98000345 ' ,/temp/*sql) in perl ?

thank u in advance
Aug 29 '07 #1
3 4656
You can do this by first opening the directory where your files are present and then implement grep.

Expand|Select|Wrap|Line Numbers
  1. opendir(DIR,"/temp");    # temp is the directory where your SQL files are 
  2.                          # present
  3. my @files = grep {/\.sql$/i} readdir(DIR);   # @files will contain all the .sql 
  4.                                              # files of your folder.
  5.  
Now, you can use grep on the files array.
Regards,
Shrek123
Aug 29 '07 #2
miller
1,089 Expert 1GB
Unix grep and Perl grep are not directly related. Instead, if you want the functionality of unix grep, then you must either access it directly via a system command, or program the logic yourself.

Here is a quick and dirty method for doing what you describe:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. my $dir = '/temp';
  4. opendir(DIR, $dir) or die "Can't open $dir: $!";
  5.  
  6. FILE:
  7. while (readdir(DIR)) {
  8.     next if !/sql$/;
  9.  
  10.     my $file = "$dir/$_";
  11.  
  12.     local *FH;
  13.     open(FH, $file) or die "Can't open $file: $!";
  14.     while (<FH>) {
  15.         if (/ 98000345/) {
  16.             print "$file\n";
  17.             next FILE;
  18.         }
  19.  
  20.     }
  21.     close(FILE);
  22. }
  23. closedir(DIR);
  24.  
- Miller
Aug 30 '07 #3
hey,

thank u..it helped me a lot..

regards
Sonia
Aug 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John E. Jardine | last post by:
Hi, Problem: Executing 's///' has a side effect on grep null string matching. If line 62, the substitution, is executed the last two values returned by grep and printed on lines 68, 69 are...
1
by: Al Belden | last post by:
Hi all, I've been working on a problem that I thought might be of interest: I'm trying to replace some korn shell scripts that search source code files with perl scripts to gain certain features...
0
by: niket patel | last post by:
Hi There is a unix server and and we access unix and perform its commond using exceed or ftp through dos. Now i want to create an application in Visual Studio C#.Net 2003 such that i can create...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
4
by: js | last post by:
Just my curiosity. Can python beats perl at speed of grep-like processing? $ wget http://www.gutenberg.org/files/7999/7999-h.zip $ unzip 7999-h.zip $ cd 7999-h $ cat *.htm bigfile $ du -h...
9
by: gyandwivedi | last post by:
what should I use in perl /in place of grep -v in unix.
2
by: ravir | last post by:
Hi, I am new to this group. I am working in Perl and shellscripts. I have a clarification regarding perl grep and pattern matching. I am writing a perl script to automate the process of code...
4
by: hassan470 | last post by:
I work in an investment bank. We have a huge log file which contains FIX messages. I have a problem to grep FIX messages within a time rage (i.e. between 9:30 am to 11 pm, those were sent by CITIBANK...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.