Quote:
Files are usually named like this alex_fontana.jun2208.txt or Fontana.Alex.062208.txt
The directory would be:
Alex Fontana
Of course we cannot be expected to give you code to cover things that are not named in that "usual" manner lol
Assuming the above 2 formats are the only 2 that will be used and that their formats are...
firstname_surname.date.txt
surname.firstname.date.txt
Code:
filename='alex_fontana.jun2208.txt'
if [ $filename =~ /_/ ]
then
firstname=$(echo $filename | awk -F. '{ print $1 }' | awk -F_ '{ print $1 }')
surname=$(echo $filename | awk -F. '{ print $1 }' | awk -F_ '{ print $2 }')
else
surname=$(echo $filename | awk -F. '{ print $1 }')
firstname=$(echo $filename | awk -F. '{ print $2 }')
fi
dirname="$firstname $surname"
If you're using an older version of bash then the pattern matching in the "if" line may not work, the following does similar...
Code:
if echo $filename | grep -q _
I was going to continue but sadly we have an emergency here at $work so maybe you'll be able to extrapolate from here
