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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk FNR Question 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I am attempting to skip lines 1-6 in a file so that they are not parsed by my awk script. I attempted to use every variation of FNR and next that I could think of, however I couldn't get it to work. Below is my very basic awk script.

BEGIN{printf ("%-17s %-10s %-15s %-15s %-10s %-8s\n", "Policy", "Type", "Stg Uni
t", "Vol Pool", "Priority", "Active")}
{printf ("%-17s %-10s %-15s%-15s %-10s %-8s\n", $1, $2, $3, $4, $7, $8)}

I tried using some of the examples below as the first line in the script, but nothing has worked thus far.

{if (FNR<6) next}

{FNR==6}

Any help would be greatly appreciated.

Thanks,

John

 
skip lines 1-6
BEGIN{printf ("%-17s %-10s %-15s %-15s %-10s %-8s\n", "Policy", "Type", "Stg Uni
t", "Vol Pool", "Priority", "Active")}
FNR>6{printf ("%-17s %-10s %-15s%-15s %-10s %-8s\n", $1, $2, $3, $4, $7, $8)}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH,

Thank you for your suggestion, but that doesn't seem to work either. Does anyone have any other suggestions?

Thanks,

John
 
not unless you help us to help you.
what is actually taking place?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
This works; I tested it.
Code:
BEGIN { fmt = "%-17s %-10s %-15s %-15s %-10s %-8s\n"
  printf fmt, "Policy", "Type", "Stg Unit",
    "Vol Pool", "Priority", "Active" }
FNR < 7 { next }
{ printf fmt, $1, $2, $3, $4, $7, $8 }
It must work, because that's the way Awk works.
Code:
FNR < 7 { next }
If the number of the record just read from the current file is less than 7, skip the rest of the code, jump to the top of the loop, and read the next record.
 
PH,

I didn't realize that nawk was installed on the server, so I tested the script with nawk and it worked fine. Have a star!!

futurelet,

I believe your solution only works with nawk as well.

Thank you both for your help.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top