AWK File processing 
Author Message
 AWK File processing



Quote:
> lables WM20.SPL
> produces labels.zpl

> If you view the lables.zpl file line 45, 52, 59, 66 I am missing my 5
> digit account number. The reason for this is because I am printing
> just $2 and $3. But I would like to make my lables.awk program smarter
> and get it to print not only $2 and  $3 but print all fields after the
> XXXX field up to and including the 5 digit account number.

> The ZPL output file is a text file for zebra printers to print label
> of customers name and account number....

> thanks,
> paul.

use a for loop, something like this:

for (i=2; i<=NF ; i++ ) {
        printf "$i "

Quote:
}

print ""

where you print $2 and $3

marc



Fri, 22 Apr 2005 09:04:58 GMT  
 AWK File processing

Quote:


> > lables WM20.SPL
> > produces labels.zpl

> > If you view the lables.zpl file line 45, 52, 59, 66 I am missing my 5
> > digit account number. The reason for this is because I am printing
> > just $2 and $3. But I would like to make my lables.awk program smarter
> > and get it to print not only $2 and  $3 but print all fields after the
> > XXXX field up to and including the 5 digit account number.

> > The ZPL output file is a text file for zebra printers to print label
> > of customers name and account number....

> > thanks,
> > paul.

> use a for loop, something like this:

> for (i=2; i<=NF ; i++ ) {
>     printf "$i "
> }
> print ""

> where you print $2 and $3

> marc

My news server didn't catch the first post, which had attachments or snipped
additional text...but I'm pretty sure that printing

    $i $i $i $i

for the line

    field1 field2 field3 field4 field5

will disappoint.

It looks like the intent is to simply print everything except the first
field.  The OP said "print all fields after the XXXX field up to and
including the 5 digit account number."  All of these suggestions DO NOT
bother to figure out which field is the five-digit account number, and DO
NOT ignore any fields after it; they DO NOT figure out which field is the
XXXX field (whatever that is); they just print everything except the first
field.  Here are a few ways...

You might try this to fix Marc's routine

    for (i = 2; i <= NF; i++)
        printf "%s ", $i
    printf "\n"

If you know NF is greater than 3, you can easily get rid of the space at the
end of the line:

    for (i = 2; i < NF; i++)
        printf "%s ", $i
    printf "%s\n", $NF

Use the form 'printf "%s", s' rather than 'printf s' to avoid bad thing when
special characters like "%" appear in s.

If you don't mind a space at the beginning, are using OFS=" " (which happens
by default), and you have an awk that rebuilds $0 like gawk does:

    $1 = ""; print

If you do mind the space,

    $1 = ""; print substr($0,2)

If FS is the default " ", you could just delete the first field with sub(),

    sub(/^[ \t]*[^ \t]*[ \t]*/,""); print

But note it's hard to exactly tie the reg exp to FS if you do this.

    - Dan



Fri, 22 Apr 2005 10:22:35 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. log file processing - awk or sed

2. Processing Configuration Files: pget.awk

3. awk output into file during processing

4. awk process in awk ??

5. processing one line in a file at a time using awk

6. Help on using AWK to process an XML file

7. Outputting info from awk and using the info to name the awk output file

8. process only last record using awk

9. Resource for awk scripts for HTML processing?

10. awk/gawk stop after processing 40mill lines

11. AWK: Problem processing first line

12. e-mail processing awk/sed

 

 
Powered by phpBB® Forum Software