Search inside a file, PERL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search inside a file, PERL
# 1  
Old 06-28-2012
Search inside a file, PERL

HEllo!!

I need a script in perl that see inside a file(file.txt) that has only one row.
The row contains only this text:

logs_yearly = 20120628113345

I want that the script does this:

"Search in the file, if the date 20120628 is actual date"

Thank you!!

---------- Post updated at 08:07 AM ---------- Previous update was at 07:46 AM ----------

Please help me!

---------- Post updated at 08:46 AM ---------- Previous update was at 08:07 AM ----------

To be more clear,

i want to see if the date that is printed inside the file, is the today date.

thank you!
# 2  
Old 06-28-2012
What have you done so far?
# 3  
Old 06-28-2012
this is what i have doone. I am completely new to this. sorry!!!

Code:
#!/usr/bin/perl
use strict;
use warnings;
my ( $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst ) = localtime(time()- 24*60*60 );
$year += 1900;
$mon += 1;
if( $mon < 9 ){
        $mon = "0" . $mon;
}
if( $mday < 9 ){
        $mday = "0" . $mday;
}
my $date = "$year$mon$mday$hour$min$sec";
my $file='/home/amino/monitorFile';
open(INFO,$file);
my @lines=<INFO>;
close(INFO);
foreach $line (@lines)
{
my @field=split(/ /,$line);
print "$field[1]\n";
}

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 06-28-2012 at 11:18 AM..
# 4  
Old 06-28-2012
Q: Why in perl? It coud be done simply in shell...

e.g.
Code:
TODAY=$(date +%Y%m%d)
if grep $TODAY yourlogfile
then
   echo "Found"
else
   echo "not found"
fi


Last edited by vbe; 06-28-2012 at 11:31 AM..
# 5  
Old 06-28-2012
I know, but this is a requirement in my work. They creates all scripts in Perl. Thank you !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies

2. Shell Programming and Scripting

Source.cshrc file inside Perl

I have a file which is basically .cshrc It contains lines such as: setenv <variable> <value>... set path=(<dir> <dir>) source <another_file>... (1 Reply)
Discussion started by: kshitij
1 Replies

3. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

4. Shell Programming and Scripting

File search in perl

Hi Gurus, Lately I have started to learn perl and need your kind support on the below query I want to search a file with name like ff_GRD_abcd_251.dat Now I will take input from user only the number i.e. 251 and the script will show o/p as the file name In the directory there are... (1 Reply)
Discussion started by: Pratik4891
1 Replies

5. Shell Programming and Scripting

Opening File names with spaces inside it !- PERL

I developed a perl code..And the excerpt from it is given below... open(HANDLE,$cmp_path) ; #reading the xml file from the file path while($file_path = <HANDLE>) I have list of XML files to read from a folder. It has some spaces inside the name of the file...I used "\"... (2 Replies)
Discussion started by: gameboy87
2 Replies

6. Programming

PERL, search and replace inside foreach loop

Hello All, Im a Hardware engineer, I have written this script to automate my job. I got stuck in the following location. CODE: .. .. ... foreach $key(keys %arr_hash) { my ($loc,$ind,$add) = split /,/, $arr_hash{$key}; &create_verilog($key, $loc, $ind ,$add); } sub create_verilog{... (2 Replies)
Discussion started by: riyasnr007
2 Replies

7. Shell Programming and Scripting

Search inside a Jar file..

Hey Guys, I need to search inside all the jar files of my directory for a specific string. Can anyone guide me as to how i can do it. I need this urgently please. More specifically i need to search for a class file name in the jar files. Thanks in advance :-) (4 Replies)
Discussion started by: srikumar_cs
4 Replies

8. Shell Programming and Scripting

doing grep inside perl file

Hi have one Perl file inside that i am defining at an array file. @temp_vmdk_files = `grep vmdk '$guest_vmx'` where my $guest_vmx=/vmfs/volumes/47e40fec-9c8bb7f7-d076-001422159f8a/BES Exchange/BES-Exchange.vmx and i am just want to do grep of "vmdk" files from the above path but when... (5 Replies)
Discussion started by: bp_vardhaman
5 Replies

9. UNIX for Dummies Questions & Answers

Search and Parse string from inside a File

Hello, I barely know the basics, but I am very determined to learn. I want to parse a few characters from each row, use that string to search another file and display the line number where I found the value in the file. I don't know if this can all be done on the command line, so I am creating a... (2 Replies)
Discussion started by: SSims
2 Replies

10. Shell Programming and Scripting

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it? using grep command.. Bit urgent.. pls..help me (2 Replies)
Discussion started by: senraj01
2 Replies
Login or Register to Ask a Question