Need Urgent Help from UNIX gurus to get specific data from a file

Hi,

I have a file monitor.txt as below...

# Times are converted to local time from GMT.
# Local Timezone: EST (GMT -05:00)

PARAM1
{
    TIME        30;
    CC1    "xxxxx";
    CC2       "xxxxx";
    CC3      "xxxxx";
    CC4       "xxxxx";
}
PARAM2
{
  4061                : First Para
  {
    TIME        0;
    CC1       "xxxxx";
    CC2       "xxxxx";
    CC3       "xxxxx";
  }
  1                   : Second para
  {
    TIME        20;
    CC1       "xxxxx";
    CC2       "xxxxx";
    CC3       "xxxxx";
  }
  2                   : third para
  {
    TIME        20;
    CC1       "xxxxx";
    CC2       "xxxxx";
    CC3       "xxxxx";
  }
  3                   : fourth para
  {
    TIME        20;
    CC1       "xxxxx";
    CC2       "xxxxx";
    CC3       "xxxxx";
  }
}

I need to write a code by which i will get an output like below:

4061 : First Para 0
1 : Second para 20
2 : third para 20
3 : fourth para 20

That means Headers and the time values of PARAM2

Thanks

With the sample input you've given, the following works. But it makes lots of assumptions and you haven't given a real specification of the input file format so it could go horribly wrong with different data:

awk '
/ : / { printf("%s : %s ", $1, substr($0, index($0, " : ") + 3))
        nt = 1
}       
/TIME/ && nt {  
        printf("%s\n", substr($2, 1, index($2, ";") - 1))
        nt = 0
}' input

As always, if you are on a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk, instead of awk.

1 Like

tooo good.. Thanks much

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums