terminal – Automator Shell Script – grep and variables – extracting and mixing textual content

on

|

views

and

comments


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):

  1. Run Shell Script (show 2 single traces of textual content beginning with “TextA” and “TextB”)
grep -i 'The supply of' "$@"
grep -i 'The barcode' "$@"
  1. New Textual content File (plain txt)

  2. Loop by means of all information (automator appears to do that mechanically)

  3. 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" "$@"
    
  4. 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.

Share this
Tags

Must-read

Torc Helps GO Virginia–Funded Effort to Align Autonomous Car Workforce Coaching Throughout the Commonwealth

BLACKSBURG, Va – March 10, 2026 – Torc, a pioneer in commercializing self-driving class 8 vans, as we speak introduced its participation in...

Union tries to grab management of works council at Tesla’s German manufacturing unit | Tesla

Europe’s largest commerce union is attempting to realize management of the works council at Elon Musk’s Tesla gigafactory close to Berlin, in an...

Nvidia and UK Wealth Fund to put money into British autonomous driving startup Oxa | Nvidia

Nvidia is investing in the British autonomous driving startup Oxa, alongside backing from the UK’s Nationwide Wealth Fund, in a lift to the...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here