Sponsored Content
Top Forums Shell Programming and Scripting find the first instance after a string Post 302312382 by josslate on Friday 1st of May 2009 08:19:31 AM
Old 05-01-2009
find the first instance after a string

I have this file (below) and need to get out specific data that appears after OSE1_1.FIX, but before OSE1_2.FIX.
Specifically I need to get all of the data after "ROW80_20:", "ROW80_21:", "ROW80_22:" & "ROW80_23:" then I need to do the same for data the appears after OSE1_2.FIX, but before OSE1_3.FIX. (again for the same ROW80_XX).
I then need to format the data so that it stays in the same rows as it has appeared in the file i.e.

file ...

Received DF_STATUS,item = OSE1_1.FIX dataFormat = 2, item =
ROW80_16: Port 2 message rate 0 0
ROW80_6:
ROW80_20:Clients: xtky2143pmd xtky2140pmd xtky2141pmd 127.60.194.1
ROW80_21: Username:mdh_ai1p2_dma mdh_tk3p1_dma mdh_tk3p2_dma tk3d_ose1
ROW80_11: Line Handler Info LHOSERDT LHFIXRDT
ROW80_22: Watchlist: 4 6 10 55
ROW80_12: Uptime 002d05h17m 002d05h17m
ROW80_23: Max watch: 30 0 12 80
Received DF_STATUS, item = OSE1_2.FIX
ROW80_16: Port 2 message rate
ROW80_6:
ROW80_20: Clients: 127.60.194.1
ROW80_10:
ROW80_21: Username: rmds1
ROW80_22: Watchlist: 45
ROW80_12: Uptime
ROW80_23: Max watch: 60
Received DF_STATUS, item = OSE1_3.FIX

required output ...

Clients: , xtky2143pmd , xtky2140pmd , xtky2141pmd , 127.60.194.1 , 127.60.194.1
Username:, mdh_ai1p2_dma , mdh_tk3p1_dma , mdh_tk3p2_dma , tk3d_ose1 , rmds1
Watchlist:, 4 , 6 , 10 , 55 , 45
Max_watch:,30 , 0 , 12 , 80 , 60


(NOTE: My existing output from this script
cat $MY_FILE | grep ROW80_20: | head -2 |awk '{print $2 "," $3 "," $4 "," $5 "," $6 "," $7 "," $8}' > $MY_CLIENTS
cat $MY_FILE | grep ROW80_21: | head -2 |awk '{print $2 "," $3 "," $4 "," $5 "," $6 "," $7 "," $8}' >> $MY_CLIENTS
cat $MY_FILE | grep ROW80_22: | head -2 |awk '{print $2 "," $3 "," $4 "," $5 "," $6 "," $7 "," $8}' >> $MY_CLIENTS
cat $MY_FILE | grep ROW80_23: | head -2 |awk '{print $2 " " $3 "," $4 "," $5 "," $6 "," $7 "," $8}' >> $MY_CLIENTS

is....

Clients:,xtky2143pmd,xtky2140pmd,xtky2141pmd,147.60.194.1,,
Clients:,147.60.194.1,,,,,
Username:,mdh_ai1p2_dma,mdh_tk3p1_dma,mdh_tk3p2_dma,tk3d_ose1,,
Username:,rmds1,,,,,
Watchlist:,4,6,10,55,,
Watchlist:,45,,,,,
Max watch:,30,0,12,80,
Max watch:,60,,,,

Many thanks for all your help!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace nth instance of string

Hi all, I have file with following content ........................... ..........TEST.......... ..........TEST.......... ..................... .....TEST.......... ..................... ..................... .....TEST.......... I want to replace nth "TEST" with "OK" using... (4 Replies)
Discussion started by: uttamhoode
4 Replies

2. UNIX for Dummies Questions & Answers

Find first instance of pattern

I am using grep to find header info in a file and print it to another file. The header info only shows up on line 3 and 4 so i really don't need to search the remainder of the file. the grep -m option doesn't work with my version of UNIX. Also I'm new to UNIX so could you please explain what... (4 Replies)
Discussion started by: NobluesFDT
4 Replies

3. Shell Programming and Scripting

Search the last instance of a string in a file

I have a big database log file which keepsgrowing daily. OS is HP UX. Here is a small part of it: Tue Jan 27 04:03:22 2009 : add session begin for mfgeb on /dev/pts/th. : Converting relative path to absolute path. : add session end. Tue Jan 27 04:03:29... (6 Replies)
Discussion started by: dinesh1178
6 Replies

4. UNIX for Dummies Questions & Answers

replacing a particular instance in a string globally

Hi, I'm trying to update the last two characters coming in a string globally in a file. Here is the sample data: file1 In file1, I want to have all instances replace where _o is appearing in the end of a word with _g. If _o is appearing in the middle or any other position except the... (2 Replies)
Discussion started by: er_ashu
2 Replies

5. Shell Programming and Scripting

awk - find first instance of string after NR==10

How do I use awk to find the NR of first instance of a specific string after eg NR==10? I need to find the first instance of the word "class" after a specific NR. (2 Replies)
Discussion started by: locoroco
2 Replies

6. Shell Programming and Scripting

awk - last instance of a string

How do I use awk to find the last occurence of a string in a file? (3 Replies)
Discussion started by: locoroco
3 Replies

7. Shell Programming and Scripting

Search text file, then grep next instance of string

I need to be able to search for a beginning line header, then use grep or something else to get the very next instance of a particular string, which will ALWAYS be in "Line5". What I have is some data that appears like this: Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line1 Line2 ...... (4 Replies)
Discussion started by: Akilleez
4 Replies

8. Shell Programming and Scripting

grep second instance of same string

Hi all, i am new to unix scripting in ksh or any shell for that matter. I have downloaded a xml file from a website and saved on my local harddrive. inside the xml, the same tag is listed multiple times. <title>Tonight</title> <title>Thursday</title> <title>Friday</title>... (6 Replies)
Discussion started by: scubasteve39
6 Replies

9. Shell Programming and Scripting

Complex find and replace only 1st instance string with dynamic combination

test.txt is the dynamic file but some of combination are fix like below are the lines ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off = disabled the test.txt can content them in any order #cat test.xt ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off =... (5 Replies)
Discussion started by: SilvesterJ
5 Replies

10. Shell Programming and Scripting

grep for a string until instance of a space

Hey guys, I'm having a bit of trouble getting this to work using either sed or grep. It's possible awk might be the ticket I need as well, but my regulat expression skills aren't quite up to the task for doing this. I'm looking to grep for the string ERROR from the following log up until any... (6 Replies)
Discussion started by: terrell
6 Replies
FMTMSG(3P)						     POSIX Programmer's Manual							FMTMSG(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
fmtmsg - display a message in the specified format on standard error and/or a system console SYNOPSIS
#include <fmtmsg.h> int fmtmsg(long classification, const char *label, int severity, const char *text, const char *action, const char *tag); DESCRIPTION
The fmtmsg() function shall display messages in a specified format instead of the traditional printf() function. Based on a message's classification component, fmtmsg() shall write a formatted message either to standard error, to the console, or to both. A formatted message consists of up to five components as defined below. The component classification is not part of a message displayed to the user, but defines the source of the message and directs the display of the formatted message. classification Contains the sum of identifying values constructed from the constants defined below. Any one identifier from a subclass may be used in combination with a single identifier from a different subclass. Two or more identifiers from the same subclass should not be used together, with the exception of identifiers from the display subclass. (Both display subclass identifiers may be used so that messages can be displayed to both standard error and the system console.) Major Classifications Identifies the source of the condition. Identifiers are: MM_HARD (hardware), MM_SOFT (software), and MM_FIRM (firmware). Message Source Subclassifications Identifies the type of software in which the problem is detected. Identifiers are: MM_APPL (application), MM_UTIL (utility), and MM_OPSYS (operating system). Display Subclassifications Indicates where the message is to be displayed. Identifiers are: MM_PRINT to display the message on the standard error stream, MM_CONSOLE to display the message on the system console. One or both identifiers may be used. Status Subclassifications Indicates whether the application can recover from the condition. Identifiers are: MM_RECOVER (recoverable) and MM_NRECOV (non- recoverable). An additional identifier, MM_NULLMC, indicates that no classification component is supplied for the message. label Identifies the source of the message. The format is two fields separated by a colon. The first field is up to 10 bytes, the second is up to 14 bytes. severity Indicates the seriousness of the condition. Identifiers for the levels of severity are: MM_HALT Indicates that the application has encountered a severe fault and is halting. Produces the string "HALT" . MM_ERROR Indicates that the application has detected a fault. Produces the string "ERROR" . MM_WARNING Indicates a condition that is out of the ordinary, that might be a problem, and should be watched. Produces the string "WARNING" . MM_INFO Provides information about a condition that is not in error. Produces the string "INFO" . MM_NOSEV Indicates that no severity level is supplied for the message. text Describes the error condition that produced the message. The character string is not limited to a specific size. If the character string is empty, then the text produced is unspecified. action Describes the first step to be taken in the error-recovery process. The fmtmsg() function precedes the action string with the pre- fix: "TO FIX:" . The action string is not limited to a specific size. tag An identifier that references on-line documentation for the message. Suggested usage is that tag includes the label and a unique identifying number. A sample tag is "XSI:cat:146" . The MSGVERB environment variable (for message verbosity) shall determine for fmtmsg() which message components it is to select when writing messages to standard error. The value of MSGVERB shall be a colon-separated list of optional keywords. Valid keywords are: label, severity, text, action, and tag. If MSGVERB contains a keyword for a component and the component's value is not the component's null value, fmtmsg() shall include that component in the message when writing the message to standard error. If MSGVERB does not include a keyword for a message component, that component shall not be included in the display of the message. The keywords may appear in any order. If MSGVERB is not defined, if its value is the null string, if its value is not of the correct format, or if it contains keywords other than the valid ones listed above, fmtmsg() shall select all components. MSGVERB shall determine which components are selected for display to standard error. All message components shall be included in console messages. RETURN VALUE
The fmtmsg() function shall return one of the following values: MM_OK The function succeeded. MM_NOTOK The function failed completely. MM_NOMSG The function was unable to generate a message on standard error, but otherwise succeeded. MM_NOCON The function was unable to generate a console message, but otherwise succeeded. ERRORS
None. The following sections are informative. EXAMPLES
1. The following example of fmtmsg(): fmtmsg(MM_PRINT, "XSI:cat", MM_ERROR, "illegal option", "refer to cat in user's reference manual", "XSI:cat:001") produces a complete message in the specified message format: XSI:cat: ERROR: illegal option TO FIX: refer to cat in user's reference manual XSI:cat:001 2. When the environment variable MSGVERB is set as follows: MSGVERB=severity:text:action and Example 1 is used, fmtmsg() produces: ERROR: illegal option TO FIX: refer to cat in user's reference manual APPLICATION USAGE
One or more message components may be systematically omitted from messages generated by an application by using the null value of the argu- ment for that component. RATIONALE
None. FUTURE DIRECTIONS
None. SEE ALSO
printf(), the Base Definitions volume of IEEE Std 1003.1-2001, <fmtmsg.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 FMTMSG(3P)
All times are GMT -4. The time now is 12:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy