Programming :: Perl : Get Maxdate From The File?
Apr 7, 2010I 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]....
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]....
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.
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].....
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]....
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]....
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.
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 RelatedI 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]....
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]...
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 RelatedI 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.
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.
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].....
How can I delete rows into text file in perl?
View 4 Replies View RelatedI 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]....
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.
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.
I am trying to make a perl script which reads data from a file and parse it. The data in the file has the following syntax
Code:
Device Physical Name : Not Visible
Device Symmetrix Name : 1234
Device Serial ID : N/A
Attached BCV Device : N/A
Device Capacity
[Code]...
Each unique record starts with "Device Physical Name". So, I have a set of records within "Device Physical Name". I want to read this set of records starting from "Device Physical Name" and ends up till next "Device Physical Name". Offcourse FS is ":", and I just want to print/or later put info in a csv file.
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.
I have found a perl script that can convert single file: ascii to hex.
However I have thousand of file that I want to convert from ascii to hex.
Here is the perl script that convert single ascii file to hex in single line:
Quote:
So I would like to read multiple file from a directory.
Then the file will be have same name file with hex data.
Here is sample of the read and write directory file.
Quote:
I'm running Apache on Centos 5.5, with active SELinux, and I'm having trouble getting my Perl script to write a file that doesn't yet exist to a folder which has the proper security context.
View 9 Replies View RelatedI'm trying to highlight some key words as tailing a log file using a perl script; about my case: I want to search for a keyworrs just once and highligt all occurrence of them. I want just highlit the keywords but not the whole line but the problems are that perl just catches the first keyword in a line and skip checking for other occurrence. for example if a line like "Error: some exception happen, Unable to process" it just highlight the error and do not process the remain part of the line where it should hilight the word "exception" and "Unable"
2-How can I do some action if for exapmle at least 4 time "unable" message appear ( not just in one line but diffrent line)in below is how I use perl search and replace : Code: s/(?:(unable|exception|warning))/e[1;31$&.......
The perl script I wrote works fine if I print the result to screen
x0_amber.pl 1 1000 0 5
But whenever I want to output to a file with
x0_amber.pl 1 1000 0 5 > x0_out
it never really prints out to the file.
It worked earlier, but I was playing with my PATH lately, I don't know if it's related to that
Using a list of names (over 4000 of them) painstakingly gleaned from the source file years ago for a database file, I want to match the names against the source file so that they can be updated with the tags <forename></forename> in the original source file.
I placed the list of names in @forenames (only posted a few of them here).
Perl script is:
I am able to get the name bracketed by the tags to appear on the console screen but don't know how to apply the output to the source file. Perhaps I need to do a match on the words then some kind of edit to surround the matching words with the xml tags? I'm a rank novice doing this as a labour of love for a friend.
Each line of the file I am sorting is in the following format:
<url> <month> <day>
For example:
[URL]
I wrote the following to sort:
Code:
#!/usr/bin/perl
$in = shift;
chomp($in);
[code]....
The script worked fine for my small testing files, but failed in my input file. The input file is 18MB and containing more than 300,000 lines. The output will contains some lines like that:
url_one 10 1
url_two 10 1
url_three 10 3
url_four 10 1
Is that because my file is too big for perl to handle ?
I am trying to create a regular expression in perl to remove all the delimiters (|) from a file. I was also thinking might I be able to use tr?
View 11 Replies View RelatedI wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.
perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";
But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.
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].....
Its my first post in here so please be patient I am trying to use regex in perl script to detect allowed words from the file and then print output to the screen.
As an example : I have text file with orders and returns :
Item2-SKU-2-11.08.2010-online
Item3-SKU-3-11.09.2010-return
Item4-SKU-4-11.09.2010-store
My question: is it possible to make sure that i am ony outputing to the screen orders based on few conditions like Item,order form e.g. online.And is it possible to have multiple matches (Item2 only diplay if ordered online etc)
Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):
There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.
If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.