How do I use awk inside my Automator workflow?
January 9, 2011 10:51 AM Subscribe
The Mac OS X Automator tool lets me run a perl script as well shell scripts, but I'd like to use awk instead. How can I fit this into my workflow? Perl appears in the popup menu of possible shells for the script, but awk does not.
I have a number of service-type Automator workflows that transform text. My public has text files that need doctoring, and I give them a nice OSX service so they can just right-click on the offending file to fix it.
In the Run Shell Script region of the workflow, I have been setting the shell to /usr/bin/perl and "Pass input: as arguments". The script text itself starts with the shebang #!/usr/bin/perl, then I go to town. (Yes, learning python is on my to-do list :-)
I'd like to start using awk for some of these, but it doesn't show up as an available shell. Is there a way I can add to Automator's list of "shells"?
If I have to run bash and pass the input to awk, what's the proper way to do it? I can't seem to get that approach to work. I'm sure I'm just being dense, but Automator's generic error is not helping.
Thanks for your help!
I have a number of service-type Automator workflows that transform text. My public has text files that need doctoring, and I give them a nice OSX service so they can just right-click on the offending file to fix it.
In the Run Shell Script region of the workflow, I have been setting the shell to /usr/bin/perl and "Pass input: as arguments". The script text itself starts with the shebang #!/usr/bin/perl, then I go to town. (Yes, learning python is on my to-do list :-)
I'd like to start using awk for some of these, but it doesn't show up as an available shell. Is there a way I can add to Automator's list of "shells"?
If I have to run bash and pass the input to awk, what's the proper way to do it? I can't seem to get that approach to work. I'm sure I'm just being dense, but Automator's generic error is not helping.
Thanks for your help!
The easiest way to use awk from the "Run Shell Script" action is to invoke awk from the Bourne shell (bash), since bash is supported by "Run Shell Script" and bash works well with awk. If you're feeling more adventuresome, you can modify /System/Library/Automator/Run Shell Script.action/Contents/Resources/Shells.plist to include awk (you'll have to write a little code to correctly handle the arguments passed from Automator).
posted by RichardP at 11:06 AM on January 9, 2011
posted by RichardP at 11:06 AM on January 9, 2011
Response by poster: Thanks for the help! I just got back to this project, and realized I hadn't updated this question.
The crucial part I had to learn is how to get the input data from the selected file into awk:
Pass input: "As arguments"
cat "$*" | awk '
{foo}
' > myoutputfile
The quotes around the variable are required if the input filename's path has spaces in it. In retrospect, my question is really a very basic question about accessing data passed by Automator into a shell script.
posted by maniabug at 10:30 AM on February 7, 2011
The crucial part I had to learn is how to get the input data from the selected file into awk:
Pass input: "As arguments"
cat "$*" | awk '
{foo}
' > myoutputfile
The quotes around the variable are required if the input filename's path has spaces in it. In retrospect, my question is really a very basic question about accessing data passed by Automator into a shell script.
posted by maniabug at 10:30 AM on February 7, 2011
This thread is closed to new comments.
posted by kindall at 11:03 AM on January 9, 2011 [1 favorite]