LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 04: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, 04:52 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 05: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, 05:37 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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, 06:22 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 05:11 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Sorry - accidental post

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


Reply



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-24-2011 11:15 PM
invoking perl inside a ksh script cheltz Linux - Newbie 4 02-09-2011 10:54 PM
LXer: Simple Arithmetic In Bash, Perl and Awk - More Porting LXer Syndicated Linux News 0 05-28-2008 08:41 AM
Linux Cheat Sheets (awk, ed, sed, bash, screen, perl) pkrumins Linux - Newbie 1 01-31-2008 03:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:30 AM.

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
Open Source Consulting | Domain Registration