Parse the Master.csv file

I’m no script expert but I’ve started a small one that I want to use to parse the /var/log/asterisk/cdr-csv/Master.csv file. The trouble is this file is not consistent. For example it has 16 fields separated by commas. In some of the entries in field #5, the callerid may have another comma in it. And fields #11, #13 & #14 don’t use quotes. This of course makes it hard to do parsing using a sed and awk. At least with my limited knowledge it does.

Can anyone offer some advice on how to parse the * log file? Is there some script available to do this?

.

Hi

Depends what you want to do, But I do have some php to display it and also search for values in it.

Ian

Thanks. I found that by parsing the /var/log/asterisk/cdr-custom/Master.csv file I could get it done with this script:

#!/bin/sh

filename="/var/log/asterisk/cdr-custom/Master.csv"

sed ‘/^"",/d’ $filename > /tmp/x
sed ‘s/",/"@@/g’ /tmp/x > /tmp/y
sed ‘s/"//g’ /tmp/y > /tmp/x

cat /tmp/y | awk -F@@ ‘{printf ("%-30s %-12s %-22s %-22s %-8s \n", $1,$2,$9,$11,$12)}’ > /tmp/x

cat -n /tmp/x > /tmp/y

.