473,769 Members | 6,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unix grep to perl

6 New Member
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...gre p( ' 98000345 ' ,/temp/*sql) in perl ?

thank u in advance
Aug 29 '07 #1
3 4686
shrek123
23 New Member
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 Recognized Expert Top Contributor
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
soniamadtha
6 New Member
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
2685
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 different than the values returned and printed when line 62 is commented out. Line 62 shouldn't have any impact on lines 67,68 & 69. Environment:
1
17721
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 such as: More powerful regular expressions available in perl Ability to print out lines before and after matches (gnu grep supports this but is not availble on our Digital Unix and AIX platforms) Make searches case insensitive by default (yes, I...
0
1672
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 an interface and from that i can connect to unix and then perform some unix command through my code. Say for example : There is one file abc.csv. on unix server.and other list of directories. Now if i want to do "ls -l" or "grep -i" command from...
4
10628
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, exploiting a vulnerability in php code. The requests are like this 216.120.231.252 - - "GET /algebra/about/history/config.php?returnpath=http://domates.1gig.biz/spread.txt? HTTP/1.1" 404 561 "-" "libwww-perl/5.805"
4
4868
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 bigfile du -h bigfile
9
3566
by: gyandwivedi | last post by:
what should I use in perl /in place of grep -v in unix.
2
2923
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 review upto some level so that the reviewer and developer's time can be reduced during the code review. In my script, I am using pattern matching and grep in many places. So, my clarification is : Is it fine to make use of grep to find a pattern in a...
4
5708
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 for ticker symbol MSFT). I tried different ways but it did not work. Could anyone please help me? Here is one of the codes in perl: #!/usr/bin/perl –w $myfile = “/tmp/fixlog.txt”; open(FH, $myfile) || die “Can not open”; while<FH>{...
47
3447
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): row+="a"
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9993
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.