I have a list of image files, which are scans of receipts. They look like this:
gas_20160710_3432.jpg
gas_20160810_242.jpg
water_20161004_4510.jpg
I would like to be able to take the list of files and turn it into a CSV file, which I can do with the command 'ls' > files.csv
.
However, I've taken care to make the file names contain a little information about the contents, and I would like to parse the file names so I can more easily work with the data when editing the CSV file in LibreOffice Calc.
Each file name has the type of receipt it is, then the date in YYYYMMDD format, and then a money amount that is written on the receipt. So, I'd like to separate that information out into different columns, as well as have one column with the full filename. So, the end result should look like this:
There is also one other issue. The date needs to be converted from YYYYMMDD to YYYY-MM-DD. Without the dashes, LibreOffice Calc seems to get confused.
Is there a way to create the CSV file I want from the directory contents from the command line?
Note that there are no other files in the directory other than the receipt scans, so there does not have to be any filtering of file types or excluding files with differently formatted names.