Script to Grep column 3 from csv file generated yesterday

Hello,

Can any one please assist how to scirpt it:

Every day a new log file is create and I want to process only the one generated yesterday and get the data of column 3 and 6.

For example today's date is 24 then I want to get the data of log file created on 23rd.

Log Files in Path_dir:\\log are in this format:
Test Log 2011-01-24.csv
Test Log 2011-01-23.csv

Each file has the same format:
Name code source server serial group
abc 123 tty1 ser1 xy12 234
john 1233 tty2 ser1 xy12 56

Appreciate your response.

Assuming we have "no , text in '"', then sed or awk can do this. Hopefulle, 5 ',' on every line!

 
sed '
  s/^[^,]*,[^,]*,\([^,]*\),[^,]*,[^,]*,\([^,]*\).*/\1 \2/
 '
cat `ls -r | head -2 | tail -1` | cut -d',' -f3,6

finds the 2nd most recent file (yesterday)
displays it
cutting out only the 3rd and 6th fields

Thanks Joeyg. The command works from CLI, I am trying to script it:

Can you please check the code:

Log files in c:\\log are
Test Log 2011-01-24.csv
Test Log 2011-01-23.csv

 
#!c:\perl\bin\perl.exe
 
#File Directory
$file_dir="C:\\log";
 
# Get yesterdays file
$last_file=`ls -r $file_dir | head -2 | tail -1`;

#Get Column3 and column6
$all=`cat "$last_file" | cut -d',' -f3,6 | sort | uniq`;
print "$all";

When I run the script, I get the following error:
C:\files\script>perl yesterday.pl
cat: Test Log 2011-01-23.csv: No such file or directory

Try like this,

$all=`cat "$file_dir\\$last_file" | cut -d',' -f3,6 | sort | uniq`;

It only executes the first half but
cut -d',' -f3,6 | sort | uniq does not execute....

Thanks

Could this help ?

$all=`cut -d "," -f3,6 $file_dir'\\'$last_file | sort | uniq`;

Yes, as long as you do not run into quoted comma in csv fields, or doubled double quotes, like this:

field1,"filed2a, field2b",field3a ""field3b"" field3c