The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 07-16-2008
Diabolist Diabolist is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 44
Here are my files:

Code:
bar_20081009_113023.csv
foo_20080909_120345.csv
munge_20061231_010020.csv
Here's the script:
Code:
#!/usr/bin/perl -w

@files = <*.csv>;
foreach $file (@files) {
  open(FH, $file);
  my @dt = ($file =~ /^(\w+)_(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})\.csv$/);
  while (<FH>) {
    chomp;
    print "$dt[1]-$dt[2]-$dt[3] $dt[4]:$dt[5]:$dt[6],$_\n";
  }
  close(FH);
}
Here's the output:
Code:
# ./test.pl
2008-10-09 11:30:23,bar1
2008-10-09 11:30:23,bar2
2008-09-09 12:03:45,foo1
2008-09-09 12:03:45,foo2
2006-12-31 01:00:20,munge1
2006-12-31 01:00:20,munge2
I'm sure it can be cleaned up a little. I'm not a very good with perl