Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with running awk prog within shell script

Status
Not open for further replies.

Fozzeebear

Technical User
Oct 20, 2003
6
0
0
GB
I have a multi-line awk program that I usually run from the command line using: nawk -f program < input > output.

I know that it is possible to run small awk programs directly from the command line, like: nawk '{print $1}' < input.

However, when I try to use this format for running the multi-line program from the command line (eventually, I want it in a shell script) it fails.

Is this possible? If so, what is the correct syntax for running a mult-line awk program from the command line or within a shell script without having to reference another file that contains the program.

Any help much will be much appreciated!







 
something like this:
Code:
nawk '
BEGIN{print &quot;Begin Section&quot;}
/pattern1/{print &quot;pattern1 found&quot;;next}
{if(NR<10){
  print &quot;Beginning of file&quot;
 }else{
  print &quot;Yet another message&quot;
}}
END{print &quot;End of file&quot;}
' /path/to/input


Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top