Programming :: Perl - Grep Open File More Then Once?

Jul 16, 2011

I am using File::Find to go through a very large tree. I am looking for all xml files and open only those that contain a tag <Updated>. I then want to capture the contents of two tags <Old> and <New>.

My problem is, after I open the file and do the first grep for <Updated> (which does work), I am unable to grep again unless I close the file and open it.

I did something like this:

Quote:

find(&check, $dir);
sub check {
if ($_ =~ /.xml/){
open(FILE,"$_");
if (grep{/Updated/} <FILE>){ # <-- works

[Code]....

View 6 Replies


ADVERTISEMENT

Programming :: Get Data From Multi Lined Text File Using Awk / Sed Or Perl - Grep And Cut Not Upto Par?

Jul 1, 2010

I need a loop that pulls out the user name into a variable and then pulls out the LastUpdate field into another variable so I can then perform a comparison against the last update field. Requirements are AIX tools including AWK, SED and Perl I am writing a script to check AIX users password expiration dates and if they are within the alerting period (ie. 7 days etc) it will email the user. I will release the full script into the public domain once completed. The text file I want to parse is formatted like:

Code:

colettel:
password = XSON0m4SdIQDw
lastupdate = 1260829398
andrewwa:

[code].....

View 4 Replies View Related

Programming :: Perl - Writing To File - Keep Open Or Only During Write?

May 24, 2011

i am working on this thread: [URL] if it is better to open a file every time i need to write to it or should i keep a file open the whole time and when i am done with the script, close it and sendmail it out?

Or i just thought of this: i could keep concatenating to a string and just sendmail when done.

View 2 Replies View Related

Programming :: Input File - Grep Within Grep

Nov 22, 2010

I need to kind of grep within grep. My input file would be something like:

[Code]....

and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:

[Code]....

View 4 Replies View Related

Programming :: Variable String File Base - Output File Doest Not Exclude The Values In Grep -av

May 1, 2011

My script.

This is may script:

Code:

Problem: Output file doest not exclude the values in grep -av

View 3 Replies View Related

Programming :: Grep The Patterns From The File?

Aug 10, 2010

I am interested in using the grep method in the shell of my CentOS machine to obtain patterns from a file and use them to search through another file and highlight the patterns found. For example:

pattern file:

one
two
three

test file:

AAAAAAAAAAAAAAAAAAAAAoneAAAAAAAAAAAAAAAAthreeAAAAAAAAAAAA

View 8 Replies View Related

Programming :: Grep A Particular Data From A File Without Using The Command

May 3, 2010

I want to know that is there any method to grep a particular data from a file without using the "cat --- | grep ' ' " command....I need to use a system call for this functionality.

View 1 Replies View Related

Programming :: Find A String In A File Without Using Grep?

Oct 27, 2010

I want to write some code to search for a specific string in a text file, but without using grep command.

View 5 Replies View Related

Programming :: Perl Find File And Then Replace String In File

Jul 28, 2009

I have script that I'm working on that updates a username in all the files that are called blah.inc for my framework. since i host a bunch of these web apps i need to do it to all of them. so I need to figure out how to update these files automagically with out me watching it to call vim every time. heres what I have so far

Code:

This finds the files but now i need to figure out how to do s/bob/fred/g on those files.

View 5 Replies View Related

Programming :: Bash Script And Grep Inside File?

Apr 2, 2010

What I'm trying to do is grep [mysqld] from inside my.cnf and then add lines inside the file should they not be there. how do i do that?

View 3 Replies View Related

Programming :: Remove Script Data From File Using Grep & Sed?

Jul 13, 2010

On one of my servers, it appears that a bunch of html files got the following code added to it...Quote:[URL]I was going to try to remove this line using grep & sed... as sample
grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g'I can get the grep portion to work...

Code:
grep "<script src='http://b.rtbn2.cn/E/J.JS'[>][<]/script[>]" *
But not the sed

View 1 Replies View Related

Programming :: Searching Pattern In Tab Delimited File Using Grep

Mar 4, 2010

Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??

View 5 Replies View Related

Programming :: Split A File To Multiple File Using Awk Or Perl?

Feb 27, 2011

I have a single file that contain multi-text something likes this:

Quote:

No. Time Source Destination Protocol Info
185 27712.068199 192.168.18.23 192.168.18.191 SMTP S: 250 2.1.5 Ok
No. Time Source Destination Protocol Info
186 27715.068293 192.168.0.50 192.168.5.2 TCP suncacao-jmxmp > 44693 [ACK] Seq=1 Ack=1 Win=64807 Len=1380

[Code].....

View 14 Replies View Related

Programming :: Grep Multiple Values In Single Pass Through Log File?

Nov 13, 2010

I have a huge binary log file. There are lets say 4 id's that I want to find in a log file. I know that those 4 id's will be present in the log file and I also know in what order they will be present. I want to find 1st id from the log then 2nd id and then third id and so on..

Simple/inefficient solution is: Loop through the id's and then grep in the log file. Problem with this solution is for each id grep will search from the beginning of the file.

Better/efficient solution would be: Sine I know the order in which id's will be present in the log file. Loop through id's, grep 1st id and then move on to grep 2nd id and so on...this way I can grep all id's in one pass. Is this solution possible ?

I have 500000 + values to find in log files and I have to find efficient solution for it.

View 2 Replies View Related

Programming :: HUGE Files - Compare A List Of Patterns From One File And Grep Them Against Another File And Print Out Only The Unique Patterns?

Aug 13, 2010

I am trying to compare a list of patterns from one file and grep them against another file and print out only the unique patterns. Unfortunately these files are so large that they have yet to run to completion. Here's the command that I used:

Code: grep -L -f file_one.txt file_two.txt > output.output Here's some example data:

Code:
>FQ4HLCS01BMR4N
>FQ4HLCS01BZNV6
>FQ4HLCS01B40PB
>FQ4HLCS01BT43K
>FQ4HLCS01CB736
>FQ4HLCS01BU3UM
>FQ4HLCS01BBIFQ

how to increase efficiency or use another command?

View 14 Replies View Related

Programming :: Perl : Get Maxdate From The File?

Apr 7, 2010

I have a input file like below :

949890;01-4477138;20101208;7003907933;0
1352305;01-32175;20101225;7005373440;0
0771586;03-975357;20091206;7004353176;0

[code]....

View 1 Replies View Related

Programming :: Perl: Parsing A Log File?

Nov 9, 2010

I have a log file (test.log) starting & ending within dash (--) as below. I am looking to write a parser for test.log. This test.log file currently has single value for one Job ID but I wish to parse for repeated N values of different Job ID - Job, User, Queue, Dispatched Date, Dispatched Time, Completed Date, Completed Time, Hosts/Processor, CPU_T and TURNAROUND. I can either output this 10 values in another .log file or dump into cgi.

The selected parameters from test.log for parsing with above 10 attributes are -

--
Job <345010>
User <xyz>
Queue <gaussian>

[code]....

View 3 Replies View Related

Programming :: Writing File In Perl/cgi?

Apr 10, 2010

I'm not able to write to a file using my perl cgi script which is as fallows:

Code:
#!/usr/bin/perl -w
use strict;
print "Content-type: text/html

[Code]....

View 4 Replies View Related

Programming :: Using Grep And Regular Expression To Find Class References In C++ File?

May 28, 2010

I'm trying to math all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp. I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working as I espected:

grep -E '^[^(/*)(//)].*[^a-zA-Z]ABCZ[]*[*(<:;,{& ]'
^[^(/*)(//)] don't math comments in the begging of the line ( // or /* )
.* followed by any character

[code]....

Well, I can get patterns like this:

class Test: public ABCZ{
class Test: public ABCZ {
class Test : public ABCZ<T>

[code]....

View 4 Replies View Related

Programming :: Cutting An Html File Apart - Perl - Sed - Awk?

Apr 13, 2010

I have an html file like this

HTML Code:

Some more HTML code... I would like to cut the above text so i get this: Sometext on multiple lines like this.Sometext on multiple lines like this.Sometext on multiple lines like this. Sometext on multiple lines like this.Sometext on multiple lines like this.

There are other HTML files with similar cuts I need to do, but once I have the method for doing one, I am sure I can do the others.

I think the two logical strings to cut between would be:

I am not sure if these strings are always the start and end of the line respectively, is this makes a lot of difference! Then the HTML tags would need to be stripped to get the text on its own.

I know the commands for removing tags, but searching for a string like class="IOSSectionTitle", and cutting everything before it etc is something I am finding challenging.

Just thought I would add that the HTML does not nec. appear on logical new lines throughout the file and there may be unexpected new lines, but as far as i know the class="IOSSectionTitle" and <img always appears as a string without any new lines between those characters.

View 4 Replies View Related

Programming :: Ngram Text File Using Perl?

Mar 6, 2011

I have a few problem. I have txt file like this:Quote:00 21 55 84 9a ff 00 1f 9e 1a 5b 00 08 00 45 00 00 4b 00 00 40 00 3f 11 9a 0e a1 8b fa 02 04 02Then, based on my txt file, I would like to generate text like this:Quote:00215584 2155849a 55849aff 849aff00 9aff001f ff001f9e 001f9e1a 1f9e1a5b 9e1a5b00 1a5b0008 5b000800 00080045 08004500 00450000 00004b00 004b0000 4b000040 00004000 0040003f 40003f11 003f119a 3f119a0e 119a0ea1 9a0ea18b 0ea18bfa a18bfa02ased in my reading, I found about ngram solution in perlbut I not really understand to edit from source code given. I m begineer user in programming language. I hope to get the solution. [URL]

View 1 Replies View Related

Programming :: Perl Script To Look At A Directory For A New File?

Oct 23, 2009

I am new to programming but I am a quick study. I have this script working.

#!/usr/bin/perl
@info=stat("/share/") or die "Can't stat share $!";
while (1) {

[code]...

View 2 Replies View Related

Programming :: Read File Names In A Dir And Its Sub Dir In Perl?

Apr 22, 2010

I am writing a script that involves reading the content of a file present in a directory and/or its sub directory. I know readdir returns all the files & DIR names in a directory but how to check weather readdir is returning a file or a directory

View 2 Replies View Related

Programming :: Reading Lines Within A File (Perl)?

Mar 16, 2011

I am trying to read certain lines within a file and give the output of the certain lines that dont equal my value, I think showing you would be easier. There is multiples of these inside one file...

Code:

LV Name /dev/vg00/lvol1
LV Status available/syncd
LV Size (Mbytes) 300lable/syncd

[code]....

I want to read everything in the file, if the status is not available then it should display the name (directly above status). If they are all availbale then do nothing. I think I know how to do it which includes putting the info in string form and placing in hash but it is proving to be out of my skill range.

View 12 Replies View Related

Programming :: Replace String In File Using Perl Or Sed

Jun 30, 2011

I have question about replacing a string in a file.

How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?

I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.

View 13 Replies View Related

Programming :: Unable To Append To A File Through Perl/CGI

Apr 6, 2010

where I'm trying to demonstrate the file locking concept through Perl/CGI.Here is the script which I tried.

Code:
#!/usr/bin/perl -w
use strict;
use warnings;
print "Content-type: text/html

[Code].....

View 2 Replies View Related

Programming :: Deleting Rows From Text File In Perl?

Jun 21, 2010

How can I delete rows into text file in perl?

View 4 Replies View Related

Programming :: Delete Multiple Lines In A File Using Perl?

Apr 15, 2011

I have a file looks like the following:

digraph topology
{
"192.168.3.254" -> "10.1.1.11"[label="1.000", style=solid];
"192.168.3.254" -> "10.1.1.12"[label="1.000", style=solid];

[code]...

Order of these lines are random... So I cannot delete line #19, for example... And you can see that top four lines I want to delete are pairs. So there might be some clever way to detect the lines, if a line has both "1.9" and "1.11", then delete the line... I am new to perl language. The following is the code I have now... I think I just need to write some code inside the while loop checking if I want to delete the line $dotline before I write to a NEW file.

Code:

#!/usr/bin/perl -w
$TOPPATH = "/tmp";
$NAME = "topology";
$FILENAME = "$TOPPATH/$NAME.dot";

[code]....

View 16 Replies View Related

Programming :: Zip A Variable With PERL Without Reading Or Writing A File?

Jun 20, 2010

There is the Archive::Zip I think I can use with Perl 5.10 but I don't know how. I don't want to read or write any files, just zip something in memory, with best compression, like

$text = "this is a test";
$zippedtext = &Zip($text);
sub Zip {

[code]...

I guess it's only a few lines.

View 3 Replies View Related

Programming :: Perl - Counting Files With File - Find

Dec 20, 2010

So this is my code:

Code:

Modification of code I found here. It works, but I don't really know why.

Q1: Why is each filter hit counted only when the conditional is not true?

Q2: I've tried taking the file type, (.old), and put it into a variable for better usability, but then the script fails.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved