LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2011, 05:46 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
invoking awk like perl or bash


when I want to save a perl file or a bash file, i start it with #!/bin/bash or #!/usr/bin/perl

However for the most part when i want to user awk i just more the file i want process into a pipe and after the pipe type "awk '{print $1}'

is there a way to invoke awk like perl and bash.

can i start my awk script with #!/usr/bin/awk ?

because from what i can see on the net, you just save the file as a plain text file and then invoke it as
awk -f <awkfileisaved> <fileIwanttoprocess>

I saw one example script where they invoked awk via

#!/bin/bash

awk '
 
Old 10-14-2011, 05:52 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Have a look at
http://www.grymoire.com/Unix/Awk.html#uh-30



Cheers,
Tink
 
1 members found this post helpful.
Old 10-14-2011, 06:09 PM   #3
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
thanks tink - this is the best overview of awk i have seen, and it answers just what i was looking for
 
Old 10-14-2011, 06:37 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
And, since Tink just pointed to a (nice) manual, the general secret is #!/bin/awk {options} -f

If you're using gawk, not POSIX AWK, you might find the bash script /usr/bin/igawk of interest. As described in the info gawk file, it implements useful @<file_name> function for including awk function in your code.
 
Old 10-14-2011, 07:22 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by PTrenholme View Post
And, since Tink just pointed to a (nice) manual, the general secret is #!/bin/awk {options} -f

If you're using gawk, not POSIX AWK, you might find the bash script /usr/bin/igawk of interest. As described in the info gawk file, it implements useful @<file_name> function for including awk function in your code.
Coincidentally that's exactly what I pointed him at in Grymoire's tutorial. :}



Cheers,
Tink
 
Old 12-20-2011, 06:11 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Sorry - accidental post

Last edited by syg00; 12-20-2011 at 06:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] need help adding letters to beginning of words from list using perl,bash or awk enteptain Programming 2 08-25-2011 12:15 AM
invoking perl inside a ksh script cheltz Linux - Newbie 4 02-09-2011 11:54 PM
LXer: Simple Arithmetic In Bash, Perl and Awk - More Porting LXer Syndicated Linux News 0 05-28-2008 09:41 AM
Linux Cheat Sheets (awk, ed, sed, bash, screen, perl) pkrumins Linux - Newbie 1 01-31-2008 04:51 PM


All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration