I'm trying to create a directory structure based on characters in the file name (the file name includes dates and times the file started being written to). I'm up to the point of having figured out how to read certain "columns" in my file name and print them. But now I can't figure out how to store them as integers. Here is my code that I'm trying to add to:
#!/bin/bash
FILES=samplefilenames*
for file in ${FILES}; do
echo "${file}" | awk -F'[-_]' '{print $8}'
done
exit $ERRORS
My filenames have '-' and '_' in them, hence the delimiters. I can make this successfully print the values I'm looking for. But I cannot get it to assign those values as variables. Literally something around the lines of
tempNum=echo "${file}" | awk -F'[-_]' '{print $8}'
Any help would be appreciated.
EDIT:
Source filename example - samplefilenames_2017-10-31_12-23-13.csv (filenames all have date/time stamps in them in this format). Directory structure I'm looking to do is add code to the existing file that places them here, and instead of having hundreds of files sitting in one location, I want them organized in directories by date. At this first level, folders of January, February, March.... (column 2) Then within each of those, subdirectories of each of the days of the month (column 3), then within each of those, one for each hour of that day column 4) Also, the column 8 in my code is just from my code, since my filenames are actually longer than my example is. I'm aware that the value needs to change accordingly.