473,396 Members | 1,689 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,396 software developers and data experts.

Find the string using grep command from the huge data fil

I want to locate a string 'Local=IN' from a file and I am sure that this string is located within 100 lines(assumption) 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 2316
chaarmann
785 Expert 512MB
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 Expert Mod 2GB
@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
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 . "\"...
2
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...
12
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...
0
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...
1
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...
2
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...
16
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...
1
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...
1
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
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,...

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.