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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Urgent Help from UNIX gurus to get specific data from a file
# 1  
Old 01-30-2013
Need Urgent Help from UNIX gurus to get specific data from a file

Hi,

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

Code:
# 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:

Code:
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

Last edited by vgersh99; 01-30-2013 at 11:40 AM.. Reason: fixed code tags
# 2  
Old 01-30-2013
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:
Code:
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.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 01-30-2013
tooo good.. Thanks much
# 4  
Old 01-30-2013
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

2. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

3. Shell Programming and Scripting

urgent<parsing data from a excel file>

Hi all, I wud like to get ur assistance in retrieving lines containing l1.My excel dataset contains around 8000 lines.I converted it into a text tab delimiter file and got the lines containing l1,My output is a list of lines containing l1 saved in a outfile.Some of d lines from my outfile s... (5 Replies)
Discussion started by: sayee
5 Replies

4. Shell Programming and Scripting

Unix gurus : how to grep this pattern?

Hello Unix gurus, My log file has entries in below format : ================================================================= 2009-01-19-01.19.24.816169+660 I8635A1158 LEVEL: Error PID : 5873782 TID : 1 PROC : aaaa APPHDL : 0-269 AUTHID : PDBCMPC... (12 Replies)
Discussion started by: Rahulpict
12 Replies

5. Shell Programming and Scripting

VI Editor - question for unix gurus !!

I have created a dummy file -demo.txt On my machine-A (oslevel-5300-08) I can display the file content in HEX format through VI editor using :%!xxd but on other machine-B (oslevel - 5300-06) , I get error as "sh: xxd: not found." machine-A: $ cat demo.txt Hello World ! I can display... (7 Replies)
Discussion started by: Rahulpict
7 Replies

6. Shell Programming and Scripting

Unix/Linux gurus...here is Q 4u

Suppose I have two files 1.txt and 2.txt. My aim is to find (Total execution time/Number of executions) then sort the result as in decreasing order. Can anyone provide me any shell/perl/awk script or a Command to do that in faster way ? 1.txt : =============================== Number of... (4 Replies)
Discussion started by: Rahulpict
4 Replies

7. Shell Programming and Scripting

Urgent: selecting unique specific content of a file using shell script

Hi, I have a file whose content and format at places is as given below. print coloumn .... coloumn .... coloumn .... skip 1 line print coloumn ... skip 1 line I need to select the following : print coloumn .... coloumn .... coloumn... (2 Replies)
Discussion started by: jisha
2 Replies

8. Shell Programming and Scripting

Help with shell script - Unix Gurus calling

Unix Gurus, I have been breaking my head to get this done..seems simple.. I need to read a flat file and based on a key word in a line, i need to skip the previous 3 lines. eg : Line1 Line2 Line3 Line4 Line5 Line6 Error Line7 Line8 Line9 Error Line10 (4 Replies)
Discussion started by: ravred
4 Replies

9. UNIX for Dummies Questions & Answers

extract some specific text file urgent pls

i have a big text file . i want to create new file as extract some specific text from the big file i am using hp ux please help (2 Replies)
Discussion started by: reyazan
2 Replies

10. UNIX for Advanced & Expert Users

Any RF unix gurus out there?

I am having a problem here. We are having several problems in regards to hung process's on unix (HPUX box), caused by my RF equipment (Mobile data capture units). these contact the host via a simply telnet session and locks the system? Is it a timeout problem as the timeout is disabled on the host. (5 Replies)
Discussion started by: Subrosa
5 Replies
Login or Register to Ask a Question