Sponsored Content
Top Forums Shell Programming and Scripting find the first instance after a string Post 302312396 by devtakh on Friday 1st of May 2009 09:16:10 AM
Old 05-01-2009
Code:
awk -F ":" '$0 ~ /ROW80_20/{n1=$2;c=c $3}
$0 ~ /ROW80_21/{n2=$2;u=u $3}
$0 ~ /ROW80_22/{n3=$2;w=w $3}
$0 ~ /ROW80_23/{n4=$2;m=m $3}END{print n1,c;print n2,u;print n3,w;print n4,m}' OFS=":" FILENAME

Cheers,
Devaraj Takhellambam
 

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(3)						     Linux Programmer's Manual							 FMTMSG(3)

NAME
fmtmsg - print formatted error messages SYNOPSIS
#include <fmtmsg.h> int fmtmsg(long classification, const char *label, int severity, const char *text, const char *action, const char *tag); DESCRIPTION
This function displays a message described by its arguments on the device(s) specified in the classification argument. For messages writ- ten to stderr, the format depends on the MSGVERB environment variable. The label argument identifies the source of the message. The string must consist of two colon separated parts where the first part has not more than 10 and the second part not more than 14 characters. The text argument describes the condition of the error. The action argument describes possible steps to recover from the error. If it is printed, it is prefixed by "TO FIX: ". The tag argument is a reference to the online documentation where more information can be found. It should contain the label value and a unique identification number. Dummy arguments Each of the arguments can have a dummy value. The dummy classification value MM_NULLMC (0L) does not specify any output, so nothing is printed. The dummy severity value NO_SEV (0) says that no severity is supplied. The values MM_NULLLBL, MM_NULLTXT, MM_NULLACT, MM_NULLTAG are synonyms for ((char *) 0), the empty string, and MM_NULLSEV is a synonym for NO_SEV. The classification argument The classification argument is the sum of values describing 4 types of information. The first value defines the output channel. MM_PRINT Output to stderr. MM_CONSOLE Output to the system console. MM_PRINT | MM_CONSOLE Output to both. The second value is the source of the error: MM_HARD A hardware error occurred. MM_FIRM A firmware error occurred. MM_SOFT A software error occurred. The third value encodes the detector of the problem: MM_APPL It is detected by an application. MM_UTIL It is detected by a utility. MM_OPSYS It is detected by the operating system. The fourth value shows the severity of the incident: MM_RECOVER It is a recoverable error. MM_NRECOV It is a nonrecoverable error. The severity argument The severity argument can take one of the following values: MM_NOSEV No severity is printed. MM_HALT This value is printed as HALT. MM_ERROR This value is printed as ERROR. MM_WARNING This value is printed as WARNING. MM_INFO This value is printed as INFO. The numeric values are between 0 and 4. Using addseverity(3) or the environment variable SEV_LEVEL you can add more levels and strings to print. RETURN VALUE
The function can return 4 values: MM_OK Everything went smooth. MM_NOTOK Complete failure. MM_NOMSG Error writing to stderr. MM_NOCON Error writing to the console. ENVIRONMENT
The environment variable MSGVERB ("message verbosity") can be used to suppress parts of the output to stderr. (It does not influence out- put to the console.) When this variable is defined, is non-NULL, and is a colon-separated list of valid keywords, then only the parts of the message corresponding to these keywords is printed. Valid keywords are "label", "severity", "text", "action" and "tag". The environment variable SEV_LEVEL can be used to introduce new severity levels. By default, only the five severity levels described above are available. Any other numeric value would make fmtmsg() print nothing. If the user puts SEV_LEVEL with a format like SEV_LEVEL=[description[:description[:...]]] in the environment of the process before the first call to fmtmsg(), where each description is of the form severity-keyword,level,printstring then fmtmsg() will also accept the indicated values for the level (in addition to the standard levels 0-4), and use the indicated printstring when such a level occurs. The severity-keyword part is not used by fmtmsg() but it has to be present. The level part is a string representation of a number. The numeric value must be a number greater than 4. This value must be used in the severity argument of fmtmsg() to select this class. It is not possible to overwrite any of the predefined classes. The printstring is the string printed when a message of this class is processed by fmtmsg(). VERSIONS
fmtmsg() is provided in glibc since version 2.1. CONFORMING TO
The functions fmtmsg() and addseverity(3), and environment variables MSGVERB and SEV_LEVEL come from System V. The function fmtmsg() and the environment variable MSGVERB are described in POSIX.1-2001. NOTES
System V and Unixware man pages tell us that these functions have been replaced by "pfmt() and addsev()" or by "pfmt(), vpfmt(), lfmt(), and vlfmt()", and will be removed later. EXAMPLE
#include <stdio.h> #include <stdlib.h> #include <fmtmsg.h> int main(void) { long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER; int err; err = fmtmsg(class, "util-linux:mount", MM_ERROR, "unknown mount option", "See mount(8).", "util-linux:mount:017"); switch (err) { case MM_OK: break; case MM_NOTOK: printf("Nothing printed "); break; case MM_NOMSG: printf("Nothing printed to stderr "); break; case MM_NOCON: printf("No console output "); break; default: printf("Unknown error from fmtmsg() "); } exit(EXIT_SUCCESS); } The output should be: util-linux:mount: ERROR: unknown mount option TO FIX: See mount(8). util-linux:mount:017 and after MSGVERB=text:action; export MSGVERB the output becomes: unknown mount option TO FIX: See mount(8). SEE ALSO
addseverity(3), perror(3) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2008-06-14 FMTMSG(3)
All times are GMT -4. The time now is 07:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy