![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to extract date with time from file | prash_b | Shell Programming and Scripting | 5 | 06-18-2008 08:30 AM |
| Processing a log file based on date/time input and the date/time on the log file | primp | Shell Programming and Scripting | 4 | 03-16-2008 11:23 AM |
| how do I put a date and time in a file name | jhamm | UNIX for Dummies Questions & Answers | 2 | 01-16-2007 09:31 AM |
| file creation date & time | alisevA3 | UNIX for Dummies Questions & Answers | 3 | 07-08-2005 05:21 AM |
| File date and time stamp | Xenon | UNIX for Dummies Questions & Answers | 1 | 10-09-2001 03:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Date and time log file
Hi,
I wrote a small perl script in unix that searches in a file and saves some information in a separate file. Since this is a log file, I would like to have the date added to file name. I have no idea where to start. output: log_010907.txt thanks ken |
|
||||
|
OP = operator ?
here is what I have from what you told me. Code:
#!/usr/bin/perl -w
use Time::localtime;
str1=`date "+%d%m%y"`;
open (FILE,"<traffic_TLG");
foreach $line (<FILE>) {
if ($line =~ m/beth/) {
open (FILE, ">>log_$str1.txt");
@items = split(",",$line);
print FILE $items[4], ",", $items[10], ",", $items[15], ";" . "\n";
close(FILE);
}
}
close (FILE);
Last edited by blowtorch; 09-03-2007 at 09:16 AM.. |
|
||||
|
there's no need to use Time::localtime. from perldoc -f localtime
Code:
# 0 1 2 3 4 5 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); put all your open() and close() commands outside the for loop. Use a different file handler, don't name both of them FILE !.. |
| Sponsored Links | ||
|
|