I am making an attempt to create an Automator Folder Motion that does the next when a number of information are moved into it. Every file has the identical format (TextA is at all times the identical; StringA and B are completely different for every file). However the knowledge I would like can be duplicated in every file, and I solely need one occasion of it:
File1.txt
TextAfile1 StringAfile1
TextBfile1 StringBfile1
TextAfile1 StringAfile1
TextBfile1 StringBfile1
An precise instance of the textual content could be:
File1.txt
The supply of TitleA
The barcode for that is 1234
The supply of TitleA
The barcode for that is 1234
File2.txt
The supply of TitleB
The barcode for that is 5678
The supply of TitleB
The barcode for that is 5678
My automator move is that this thus far (Folder motion receives information added to Folder):
- Run Shell Script (show 2 single traces of textual content beginning with “TextA” and “TextB”)
grep -i 'The supply of' "$@"
grep -i 'The barcode' "$@"
-
New Textual content File (plain txt)
-
Loop by means of all information (automator appears to do that mechanically)
-
Run Shell Script (Delete “TextA” and TextB from the start of all traces so all of them begin with the textual content StringA that instantly follows)
sed -e "s/The supply of //g" "$@" sed -e "s/The barcode for that is //g" "$@" -
Run Shell Script (alphabetize type)
cat "$@" | type
The ensuing Textual content file ought to appear like this:
TitleA 1234
TitleB 5678
...
TitleZ ####
Proper now I am getting this (with out quotes):
"/customers/path/to/file1.txt:The supply of TitleA"
"/customers/path/to/file1.txt:The supply of TitleA"
"/customers/path/to/file2.txt:The supply of TitleB"
"/customers/path/to/file2.txt:The supply of TitleB"
"/customers/path/to/file1.txt:The barcode for that is 1234"
"/customers/path/to/file1.txt:The barcode for that is 1234"
"/customers/path/to/file2.txt:The barcode for that is 5678"
"/customers/path/to/file2.txt:The barcode for that is 5678"
I am making an attempt to delete the trail, delete the previous textual content, and take away the duplicates. So ideally I will find yourself with:
TitleA 1234
TitleB 5678
Bonus could be to additionally type the ultimate txt file alphabetically. However I may accept pasting it into Excel and sorting there and so on. though sorting in script could be higher if not too dificult.
Am I heading in the right direction in any respect? I’ve tried all completely different combos of this workflow and it appears like there is a basic flaw with it.
