This bash script will work on the Report.txt file created with Automator:
#!/bin/bash
while read line
do
name=$line
s=$( echo "$name" | grep -Eo '[0-9]{1,}' )
a=($s)
for i in "${a[@]}"
do
printf "%s %s\n" "$i": "$line" >> ~/Desktop/Report2.txt
done
done < ~/Desktop/Report.txt
sort ~/Desktop/Report2.txt > ~/Desktop/ReportSorted.txt
This can easily be incorporated into the original Automator Workflow.
Just replace the Run Shell Script Action with:
textutil -stdout -convert txt "$1" | grep -E '[0-9]{1,}' > ~/Desktop/Report.txt
while read line
do
name=$line
s=$( echo "$name" | grep -Eo '[0-9]{1,}' )
a=($s)
for i in "${a[@]}"
do
printf "%s %s\n" "$i": "$line" >> ~/Desktop/Report2.txt
done
done < ~/Desktop/Report.txt
sort ~/Desktop/Report2.txt > ~/Desktop/ReportSorted.txt
rm "$1" ~/Desktop/Report.txt ~/Desktop/Report2.txt
The Workflow is:
So, if the PDF is:
"I am 20. My friend is 30. Her husband is 40."
"I am 30. My friend is 40. Her husband is 50."
ReportSorted.txt will be:
20: "I am 20. My friend is 30. Her husband is 40."
30: "I am 20. My friend is 30. Her husband is 40."
30: "I am 30. My friend is 40. Her husband is 50."
40: "I am 20. My friend is 30. Her husband is 40."
40: "I am 30. My friend is 40. Her husband is 50."
50: "I am 30. My friend is 40. Her husband is 50."