Sponsored Content
Top Forums Shell Programming and Scripting Search for string and print top and bottom line Post 302554866 by bombcan on Tuesday 13th of September 2011 08:21:17 AM
Old 09-13-2011
Search for string and print top and bottom line

Hi Folks

I need a one liner to parse through a log and if the string is found print the line above, the line with the string and the line below.

example:

The ball is green and blue
Billy through the ball higer.
Jane got hurt with the ball.

So if I search for Billy I would need the 3 lines above printed.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search for a pattern from bottom to top.

Hi, I have a file, which is having a pattern "SEARCH" somewhere towards end of the file, if i am giving " grep -i "SEARCH" $File" , it is taking too much time as file is very big. So i want to search for the pattern from the back side of the file, how can we search for a pattern in bottom... (5 Replies)
Discussion started by: Prat007
5 Replies

2. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

3. Shell Programming and Scripting

Search a string and print the rest of line

Hi Guys, I need to search a string and print the rest of the lines... input: 8 0 90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n output: 00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n Actually i don even need the first "00".. any suggestions is appreciated..... (13 Replies)
Discussion started by: mac4rfree
13 Replies

4. Shell Programming and Scripting

awk print second line after search string

I have multiple config files where I need to pull the ip address from loopback3. The format is the same in every file, the ip is the second line after interface loopback3. interface loopback2 loopback description router ID ip address 192.168.1.1 interface loopback3 loopback description... (3 Replies)
Discussion started by: numele
3 Replies

5. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies

6. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

7. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

8. Shell Programming and Scripting

Print n lines from top and n lines from bottom of all files with .log extenstion

Oracle Linux 6.4 In a directory I have more than 300 files with the extension .log I want the first 5 and last 5 lines of these .log files to be printed on screen with each file's name. Expected output : Printing first 5 and last 5 lines of FX_WT_Feb8_2014.log !! Authentication... (7 Replies)
Discussion started by: kraljic
7 Replies

9. Shell Programming and Scripting

How to print from bottom to top?

Hi, i have a file which contains PID and wanted to execute kill command. but the thing is, when killing PID's needs to kill PID from bottom to top. Please help INPUT 21414 sh -c extract.ksh ASA 21416 /bin/ksh extract.ksh ASA 21428 /usr/bin/perl -w /var/tmp/tempperl.21416 ASA... (4 Replies)
Discussion started by: reignangel2003
4 Replies

10. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies
PVALUE(1)						      General Commands Manual							 PVALUE(1)

NAME
pvalue - convert RADIANCE picture to/from alternate formats SYNOPSIS
pvalue [ options ] [ file ] pvalue -r [ options ] [ file1 [ file2 file3 ] ] DESCRIPTION
Pvalue converts the pixels of a RADIANCE picture to or from another format. In the default mode, pixels are sent to the standard output, one per line, in the following ascii format: xpos ypos red green blue If no file is given, the standard input is read. The reverse conversion option (-r) may be used with a single input file or when reading from the standard input, but if the second form is used with three separate input files, the three primaries are presumed to be separated in these files. -u Print only unique values in the output, skipping runs of equal pixels. Specifying +u turns this option off, which is the default. -o Print original values, before exposure compensation. If the input file is in XYZE format, the Y (green) channel will correspond to units of candelas/meter^2. Otherwise, the RGB values should be in spectral watts/steradian/meter^2. Specifying +o uses final exposed values, which is the default. -h Do not print header. Specifying +h causes the header to be printed, which is the default. -H Do not print the resolution string. (See also the -r option below.) Specifying an input resolution for reverse conversion also turns this option off. Specifying +H causes the resolution string to be printed, which is the default. -s nbytes Skip the specified number of bytes on the input header. This option is useful for skipping unintelligible headers in foreign file formats. (Does not work when reading from standard input.) -e exposure Adjust the exposure by the amount specified. If the exposure is being given as a conversion factor, use +e instead, so an EXPO- SURE line will not be recorded in the header (if any). -g gamma Set gamma correction for conversion. When converting from a RADIANCE picture to another format, the inverse gamma is applied to correct for monitor response. When converting to a RADIANCE picture (-r option), the gamma is applied directly to recover the linear values. By default, gamma is set to 1.0, meaning no gamma correction is performed. -d Data only, do not print x and y pixel position. -da Same as -d. -di Print ascii integer values from 0 to 255+. If +di is given, the integer values will be preceded by the x and y pixel locations. -db Output binary byte values from 0 to 255. -dw Output binary 16-bit words from 0 to 65535. -dW Output binary 16-bit words from 0 to 65535, byte-swapped. -df Output binary float values. -dF Output byte-swapped binary float values. -dd Output binary double values. -dD Output byte-swapped binary double values. -R Reverse ordering of colors so that the output is blue then green then red. The default ordering (specified with +R) is red then green then blue. -n The RGB values are non-interleaved, meaning that all the red, green and blue data are stored together in separate chunks. Inter- leaving may be turned on with the +n option, which is the default. -b Print brightness values rather than RGB. Specifying +b turns this option off, which is the default. -pP Put out only the primary P, where P is one of upper or lower case 'R', 'G' or 'B' for red, green or blue, respectively. This option may be used to separate the Radiance primaries into three files with three separate runs of pvalue, or only one file when only one primary is needed. Note that there is no space between this option and its argument. -r Perform reverse conversion. Input is in the format given by the other options. The x and y resolution must be specified on the command line, unless the image file contains a Radiance resolution string at the beginning (see -H option above and -y option below). Specifying +r converts from a Radiance picture to other values, which is the default. -p xr yr xg yg xb yb xw yw On reverse conversion, RGB input uses the given set of color primaries. These are written into the output header with the PRI- MARIES variable. -pXYZ On reverse conversion, input is in CIE XYZ coordinates, rather than RGB. The Y channel is assumed to be in candelas/meter^2. -y res Set the output y resolution to res. If +y is specified, then the scanlines are assumed to be in increasing order (ie. bottom to top). The default value for this option is 0, which means that the picture size and scanline order must appear as the first line after the header (if any) in the input file. Either an upper or lower case 'Y' may be used for this option. Since Radiance files always contain such a line, this option has no effect for forward conversions. +x res Set the output x resolution to res. If -x is specified, then the scanlines are assumed to be in decreasing order (ie. right to left). The ordering of the -y and +x options determines whether the scanlines are sorted along x or along y. Most Radiance pic- tures are sorted top to bottom, then left to right. This corresponds to a specification of the form "-y yres +x xres". Either an upper or lower case 'X' may be used for this option. Like the -y option, -x options have no effect for forward conversions. EXAMPLE
To look at the original, unique pixels in picture: pvalue -o -u picture | more To convert from a 512x400 8-bit greyscale image in bottom to top, left to right scanline ordering: pvalue -r -db -b -h +y 400 +x 512 input.im > flipped.hdr pflip -v flipped.hdr > final.hdr AUTHOR
Greg Ward BUGS
The -r option does not work with the -u option. Also, input pixel locations are ignored during a reverse conversion, so this information is not used in determining the scanline ordering or picture size. SEE ALSO
getinfo(1), pcompos(1), pfilt(1), pflip(1), protate(1), ra_xyze(1), rpict(1), rtrace(1), rvu(1) RADIANCE
1/15/99 PVALUE(1)
All times are GMT -4. The time now is 09:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy