How to convert FDF to CSV?
Option A:
awk -F "[()]" '{ if ($1=="/V ") value[$2];} \
END {printf( "CompanyName\tEmailAddress\t\tCountryOrRegion\n" ); \
for (x in value)printf("%s\t", x);print "" ; \
}' filled_form.fdf > filled_form.CSV
Option B:
grep -oP '(?<=\/T \(txt).*(?=\))' filled_form.fdf |awk '{ORS=(NR%3?",":RS)}1'; \
grep -oP '(?<=\/V \().*(?=\))' filled_form.fdf |awk '{ORS=(NR%3?",":RS)}1';
Short version of above command would be:
paste -sd, <(grep -oP '(?<=\/T \(txt).*(?=\))' filled_form.fdf) <(grep -oP '(?<=\/V \().*(?=\))' filled_form.fdf)
Option C:
awk 'NR%2==0{type[$0]} NR%2{value[$0]} END{for (x in type)printf("%s\t", x);print "" ;for (y in value)printf("%s\t", y);print "" ;}' <(grep -oP '(?<=\/T \(txt|\/V \().*(?=\))' filled_form.fdf)
How to convert unfriendly CSV to friendly CSV ?
Option A:
awk -F: '{ if ($1=="FieldValue") value[$2];} \
END {printf( "CountryOrRegion\tCompanyName\tEmailAddress\n" ); \
for (x in value)printf("%s\t", x) ;print ""; \
}' filled_form.csv > friendly_filled_form.CSV
Option B:
grep -oP '(?<=FieldName: txt).*' filled_form.csv |awk '{ORS=(NR%3?",":RS)}1'; \
grep -oP '(?<=FieldValue: ).*' filled_form.csv |awk '{ORS=(NR%3?",":RS)}1'
*Note that this command is one linear. so for running it you have to type/copy both line.
And short version for this one would be:
paste -sd, <(grep -oP '(?<=FieldName: txt).*' filled_form.csv) <(grep -oP '(?<=FieldValue: ).*' filled_form.csv)
Option C:
awk 'NR%2{type[$0]} NR%2==0{value[$0]} END{for (x in type)printf("%s\t", x);print "" ;for (y in value)printf("%s\t", y);print "" ;}' <(grep -oP '(?<=FieldName: txt|FieldValue: ).*' filled_form.csv)
or even this one:
awk 'NR%2{type[$0]} NR%2==0{value[$0]} END{for (x in type)printf("%s\t", x);print "" ;for (y in value)printf("%s\t", y);print "" ;}' <(awk -F'FieldValue: |FieldName: txt' 'NF>1{print $2}' filled_form.csv)
How to convert PDF to CSV?
I will complete the solution with pdfgrep
tomorrow but if you want to try it for yourself, here is the command:
pdfgrep 'CompanyName|CountryOrRegion|EmailAddress' filled_form-submit_format_fdf.pdf
It needs to work on output format. If you want to get only whole words, use the -C 0
option. good luck and I hope helps ;)
Best Answer
A quick and dirty example using code from the pyinotify project [http://github.com/seb-m/pyinotify]
You will need to change the WATCHED_DIR to your directory containing ODT files. Also remember to install unoconv first.
Save this as odtwatcher.py and then run it in the background