AWK program question

BEGIN {
        FS = "[\t]+";
        first_attr = 1;
        first_state = 1;
        more_attr = 1;
        more_state = 1;
        hold_date = " ";
        }

/^STATE/ {
        # Remember the last one

        state = $2;
        if (first_state)
                {
                #
                # Make note of the first state date (Submitted)
                #

# Look for the completed state by presettting to the 4th line value = to "Completed"

                first_state = 0;

split($NF,a," ");
who = a[2];
                hold_date = who;
# Use split to dissect the ling into separte array values separated by spaces


                }

        if (more_state)
                {
                more_state = 4;
split($NF,a," ");
who = a[2];
                }

date = hold_date;
        next;
        }

$2 ~ /Priority/ { priority = $NF; next; }


#
# Assume that the first attribute is the title
#

$1 ~ /ATTRIBUTE/ {
        if (first_attr)
                {
                title = $NF;
                first_attr = 0;
#               next;
        }


        if (more_attr)
        {
        more_attr = 4;
        split($NF,a," ");
        impacts = a[2];
        }

                next;
        }


END {
        printf("%-9.9s %-8.8s %-8.8s %-8.8s %-6.6s %-10.10s  %-40.40s\n",
                ARGV[1], state, who, priority, impacts, date, title);
        }' $file >> $OUTFILE

done


###############################################################
This is the data ################################################################
LATEST_VERSION  1.2
LAST_MODIFIED   1003758812      2001/10/22,09:53:32
TIME_CHECKED_IN 1003758812      2001/10/22,09:53:32
CHECKSUM        0
FILE_ID         000000000
IS_A_BRANCH     0
IS_TERMINATED   0
CHECKED_OUT     0
BINARY          0
NUM_BRANCHES    0
NUM_STATES      5
EXPAND_KEYWORDS 0
STATE           Submitted               2001/01/29,13:32:16 twalter
STATE           No-Action               (skipped)
STATE           Active          (skipped)
STATE           Completed               (skipped)
STATE           Closed          2001/10/22,09:53:31 twalter
ATTRIBUTE       Title           Overloading Plant Alarms
ATTRIBUTE       Priority                High
ATTRIBUTE       Impact          Minimal
ATTRIBUTE       Projection              981349200       02/05/2001
ATTRIBUTE       Scope           Code,
ATTRIBUTE       Approved                0
ATTRIBUTE       Responsibility          Engineering

Help I need someone who can interpret some awk statements for me..

How can check for a second record that starts with /ATTRIBUTE/ but also has the pattern /Impact/ in the record. The reason for this is the /Impact/ record can be in any one of the records. So first I need the one with the /Title/ then I need the record with the /Impact/

thanks for all who help!


Don
dprice7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gheistCommented:
^ATTRIBUTE.*Impact
0
gheistCommented:
For more information:

http://zh.wikipedia.org/wiki/SQL
0
ozoCommented:
/ATTRIBUTE\W+Impact/ {
    impacts = $NF;
}

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dprice7Author Commented:
ozo,

Please explain what the /ATTRIBUTE\W+Impact/ does

thanks,

Don
0
dprice7Author Commented:
gheist,

Since the page you sent me is in another language it is not very useful to me.

Please explain what the ^ATTRIBUTE.*Impact does..

thanks,

Don
0
ozoCommented:
It matches lines containing "ATTRIBUTE" and "Impact" separated by one or more characters that  are  not  word-constituent.
The following block is executed on lines which match the pattern.
0
ozoCommented:
/^ATTRIBUTE.*Impact/
would be a pattern that matches "ATTRIBUTE" at the beginning of the line, followed by 0 or more of any character, followed by "Impact"
0
dprice7Author Commented:
ozo,

So does it require that one loop sits inside the other to get both values in separate records or can they stay separate?

$1 ~ /ATTRIBUTE/ {
        if (first_attr)
                {
                title = $NF;
                first_attr = 0;
#               next;
        }

/ATTRIBUTE\W+Impact/ {
    impacts = $NF;
}
0
ozoCommented:
/ATTRIBUTE\W+Impact/ {
    impacts = $NF;
}
would be a separate pattern-action statement
If you want something that goes inside the $1 ~ /ATTRIBUTE/ { you could do something like
$1 ~ /ATTRIBUTE/ {
        if (first_attr)
                {
                title = $NF;
                first_attr = 0;
#               next;
        }
        if( $2 ~ /Impact/ ){
              impacts = $3;
       }
}
0
gheistCommented:
what you look for is called regular expressions :

http://www.regular-expressions.info/tutorial.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dprice7Author Commented:
ozo,

It gives me parse errors when I do this...

#
# Assume that the first attribute is the title
#

$1 ~ /ATTRIBUTE/ {
        if (first_attr)
                {
                title = $NF;
                first_attr = 0;
                next;
        }
        }
/ATTRIBUTE\W+Impact/{
impacts= $NF;
}
               
                next;



END {  
0
gheistCommented:
brackets do not match ....
0
dprice7Author Commented:
gheist,

If you are talking about the bracket for END it has one.. it just didn't copy..

END {
        printf("%-9.9s %-8.8s %-8.8s %-8.8s %-6.6s %-10.10s  %-40.40s\n",
                ARGV[1], state, who, priority, impacts, date, title);
        }' $file >> $OUTFILE

0
ozoCommented:
my awk complains about the "next" outside of any {}
0
dprice7Author Commented:
ozo,

thanks for hanging in there till the end with me.

gheist, appreciate your input as well

thanks again,

Don
0
gheistCommented:
why you have program so complex ?


awk -F" " '/Title/ {printf $3} /LastData/ { print $3 $4 }'

or so ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.