473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find the string using grep command from the huge data fil

14 New Member
I want to locate a string 'Local=IN' from a file and I am sure that this string is located within 100 lines(assumptio n) from the beginning of the file out of 5000 lines. The 100th line start with the word '--Begin'. So in order to locate the string from only 100 line, I think copying all the file content into any array is not a good idea.

I want the grep command to exist in the script.

I have the following code. I need this to be modified as per the above condition.

Your help will be appreciated.

Thanks


Expand|Select|Wrap|Line Numbers
  1. $fname="file.txt";
  2.  
  3. open(FH,$fname);
  4. @file_content=<FH>;
  5.  
  6. foreach (@file_content){
  7.  
  8. my $match_text=grep {"Local=IN"},@file_content;
  9.  
  10. Last if($match_text);
  11.  
  12.   else {
  13.  
  14. open(WH,"temp.log");
  15. print WH "$\n";
  16. if (/Testing Option 0 ok/){
  17. print "Local=IN\n";
  18.    }
  19.  
  20. unlink($fname);
  21. rename(temp.log,"$fname");
  22. }


Find the string using grep command from the huge data file
Aug 28 '10 #1
2 2324
chaarmann
785 Recognized Expert Contributor
You have done already 14 postings, you should know about code tags. So why don't you use them?

You wrote "Find the string using grep command from the huge data file". Is this line copied from a homework assignment?
Anyway, to do it this way, just use
Expand|Select|Wrap|Line Numbers
  1. my $lineFound=`head -100 file.txt | grep 'local=IN'`; # backticks! 
Aug 31 '10 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
@powerfulperl I fully concur with @chaarmann. This is the last time I nicely add the code tags to your posts. Next time will result in being action being taken.

Code tags are not hard to use and are REQUIRED when posting code in the forums. You can either read the FAQ to figure out how to do it manually, or, after you input your code, highlight the code and hit the "#" symbol in the top of the editor box as it will automatically add them when you click it.

It is not difficult and is required. Again, this is your last warning!

Regards,

Jeff
Aug 31 '10 #3

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

Similar topics

14
9728
by: Bruce A. Julseth | last post by:
When I execute this SQL statement in my PHP code, I get an error "File '.\Address.txt' not found (Errcode: 2)" $File = addslashes(".\Address.txt"); $SQL = "Load Data InFile \"" . $File . "\" into table addresses"; $result = mysql_query($SQL) or die(mysql_error()); The file is located in the same directory as my .PHP file. How do I...
2
10306
by: Matt | last post by:
The JSP page needs to send XML request string to another JSP page when the user clicks submit button, I wonder how to get started because when user click submit button, it will send the form to page2.jsp. <form action="page2.jsp" method="POST"> Name: <input type="text" name="fname"> //etc.. controls <input type="submit"> </form>
12
2305
by: Sezai YILMAZ | last post by:
Hi, I use PostgreSQL 7.4 for storing huge amount of data. For example 7 million rows. But when I run the query "select count(*) from table;", it results after about 120 seconds. Is this result normal for such a huge table? Is there any methods for speed up the querying time? The huge table has integer primary key and some other indexes for...
0
6027
by: den 2005 | last post by:
Hi everybody, I am not familiar using Gridview, I created a Gridview with Edit Command Button, but when I click the update Command button this error message below is displayed, what and where is the problem? I am confused. Can anyone show me exactly to do edit process of Gridview using Edit Command button properly? Thanks. Error Message:...
1
10472
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 ...
2
1697
by: bravo | last post by:
hello every one i have previously posted problem regarding using join on huge data set say(records upto 10 million) . but didnt get satisfactory reply.... what i found that if i use join it brings disaster .... but if i cant use joins then how to tackle situation where the output is obtained by running query on both tables... in mysql is...
16
2028
by: pereges | last post by:
ok so i have written a program in C where I am dealing with huge data(millions and lots of iterations involved) and for some reason the screen tends to freeze and I get no output every time I execute it. However, I have tried to reduce the amount of data and the program runs fine. What could possibly be done to resolve this ?
1
1621
by: psbasha | last post by:
Hi , I have to parse a huge data of 3GB and store it in the dictnoray.After storing the data ,I need to do lot of calculations and write to the output file.The application is working for 500 MB file data,but for 3GB file it throwing Out of Memory message on the Python Editor. Could you please help me with the best approach of data handling...
1
2164
by: rameshjumgam | last post by:
Hi in my file im having value like cpu speed is 1000.000 but i wants to pick only before special character .(dot) please help me someone ? thanks in advance
0
7411
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...
0
7669
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7439
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...
0
5987
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3468
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...
1
1901
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
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
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...

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.