Sponsored Content
Top Forums Shell Programming and Scripting Help in printing n number of lines if a search string matches in a file Post 302788829 by RudiC on Tuesday 2nd of April 2013 02:30:32 PM
Old 04-02-2013
Please use code tags as required by forum rules!

One option, just dreamed up from the blue sky: Set up a counter, after the read, incremented by 0 until your grep matches. Then, increment by 1 and collect $line into the message file. When the counter hits 10, send the mail, reset increment to 0, clear the file, and continue.
Or, do the entire thing in e.g. awk.

BTW, you can take all the variable assignments out of the loop as it seems they remain constant.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

question about printing number of lines in a file

as the title, I had try use "wc -l test.txt" but it give me "<many spaces> 384 test.txt" but the result I want is just "384" could any person can help me that? Thx:( (5 Replies)
Discussion started by: a8111978
5 Replies

2. Shell Programming and Scripting

Get line number when matches a string

If I have a file something like as shown below, ARM*187878*hjhj BAG*88778*jjjj COD*7777*kkkk BAG*87878*kjjhjk DEF*65656*89989*khjkk I need the line numbers to be added with a colon when it matches the string "BAG". Here in my case, I need something like ARM*187878*hjhj... (4 Replies)
Discussion started by: Muthuraj K
4 Replies

3. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

4. Shell Programming and Scripting

Printing 10 lines above and below the search string: help needed

Hi, The below code will search a particular string(say false in this case) and return me 10 lines above and below the search string in a file. " awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print("***********************************");print;c=a;}b{r=$ 0}' b=10 a=10 s="false" " ... (5 Replies)
Discussion started by: vimalm22
5 Replies

5. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

6. Shell Programming and Scripting

How to search number of occurrences of a particular string in a file through vi editor?

i have one file, i am doing 'vi Filename' now i want to search for particular string and i want to know how many times that string occurs in whole file (5 Replies)
Discussion started by: sheelsadan
5 Replies

7. Shell Programming and Scripting

How to Search string(which is in 2 lines) in a file?

Hello, I want to search 2 lines from the file. I wanted to display all such matches. Example file: ================== Testfile is test TEST1 TEST2 testing the file string to do testing TEST1 TEST2 sample strings ================= I wanted to search the file with 2 lines " TEST1... (3 Replies)
Discussion started by: balareddy
3 Replies

8. Shell Programming and Scripting

Required 3 lines above the file and below file when string matches

i had requirement like i need to get "error" line of above 3 and below 3 from a file .I tried with the below script.But it's not working. y='grep -n -i error /home/file.txt|cut -c1' echo $y head -$y /home/file.txt| tail -3 >tmp.txt tail -$y /home/file.txt head -3 >>tmp.txt (4 Replies)
Discussion started by: bhas85
4 Replies

9. Shell Programming and Scripting

Replace all string matches in file with unique random number

Hello Take this file... Test01 Ref test Version 01 Test02 Ref test Version 02 Test66 Ref test Version 66 Test99 Ref test Version 99 I want to substitute every occurrence of Test{2} with a unique random number, so for example, if I was using sed, substitution would be something... (1 Reply)
Discussion started by: funkman
1 Replies
GLBEGINQUERY(3G)						   OpenGL Manual						  GLBEGINQUERY(3G)

NAME
glBeginQuery - delimit the boundaries of a query object C SPECIFICATION
void glBeginQuery(GLenum target, GLuint id); PARAMETERS
target Specifies the target type of query object established between glBeginQuery and the subsequent glEndQuery(). The symbolic constant must be one of GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_PRIMITIVES_GENERATED, GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, or GL_TIME_ELAPSED. id Specifies the name of a query object. C SPECIFICATION
void glEndQuery(GLenum target); PARAMETERS
target Specifies the target type of query object to be concluded. The symbolic constant must be one of GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_PRIMITIVES_GENERATED, GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, or GL_TIME_ELAPSED. DESCRIPTION
glBeginQuery and glEndQuery() delimit the boundaries of a query object. query must be a name previously returned from a call to glGenQueries(). If a query object with name id does not yet exist it is created with the type determined by target. target must be one of GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED, GL_PRIMITIVES_GENERATED, GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, or GL_TIME_ELAPSED. The behavior of the query object depends on its type and is as follows. If target is GL_SAMPLES_PASSED, id must be an unused name, or the name of an existing occlusion query object. When glBeginQuery is executed, the query object's samples-passed counter is reset to 0. Subsequent rendering will increment the counter for every sample that passes the depth test. If the value of GL_SAMPLE_BUFFERS is 0, then the samples-passed count is incremented by 1 for each fragment. If the value of GL_SAMPLE_BUFFERS is 1, then the samples-passed count is incremented by the number of samples whose coverage bit is set. However, implementations, at their discression may instead increase the samples-passed count by the value of GL_SAMPLES if any sample in the fragment is covered. When glEndQuery is executed, the samples-passed counter is assigned to the query object's result value. This value can be queried by calling glGetQueryObject() with pnameGL_QUERY_RESULT. If target is GL_ANY_SAMPLES_PASSED or GL_ANY_SAMPLES_PASSED_CONSERVATIVE, id must be an unused name, or the name of an existing boolean occlusion query object. When glBeginQuery is executed, the query object's samples-passed flag is reset to GL_FALSE. Subsequent rendering causes the flag to be set to GL_TRUE if any sample passes the depth test in the case of GL_ANY_SAMPLES_PASSED, or if the implementation determines that any sample might pass the depth test in the case of GL_ANY_SAMPLES_PASSED_CONSERVATIVE. The implementation may be able to provide a more efficient test in the case of GL_ANY_SAMPLES_PASSED_CONSERVATIVE if some false positives are acceptable to the application. When glEndQuery is executed, the samples-passed flag is assigned to the query object's result value. This value can be queried by calling glGetQueryObject() with pnameGL_QUERY_RESULT. If target is GL_PRIMITIVES_GENERATED, id must be an unused name, or the name of an existing primitive query object previously bound to the GL_PRIMITIVES_GENERATED query binding. When glBeginQuery is executed, the query object's primitives-generated counter is reset to 0. Subsequent rendering will increment the counter once for every vertex that is emitted from the geometry shader, or from the vertex shader if no geometry shader is present. When glEndQuery is executed, the primitives-generated counter is assigned to the query object's result value. This value can be queried by calling glGetQueryObject() with pnameGL_QUERY_RESULT. If target is GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, id must be an unused name, or the name of an existing primitive query object previously bound to the GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN query binding. When glBeginQuery is executed, the query object's primitives-written counter is reset to 0. Subsequent rendering will increment the counter once for every vertex that is written into the bound transform feedback buffer(s). If transform feedback mode is not activated between the call to glBeginQuery and glEndQuery, the counter will not be incremented. When glEndQuery is executed, the primitives-written counter is assigned to the query object's result value. This value can be queried by calling glGetQueryObject() with pnameGL_QUERY_RESULT. If target is GL_TIME_ELAPSED, id must be an unused name, or the name of an existing timer query object previously bound to the GL_TIME_ELAPSED query binding. When glBeginQuery is executed, the query object's time counter is reset to 0. When glEndQuery is executed, the elapsed server time that has passed since the call to glBeginQuery is written into the query object's time counter. This value can be queried by calling glGetQueryObject() with pnameGL_QUERY_RESULT. Querying the GL_QUERY_RESULT implicitly flushes the GL pipeline until the rendering delimited by the query object has completed and the result is available. GL_QUERY_RESULT_AVAILABLE can be queried to determine if the result is immediately available or if the rendering is not yet complete. NOTES
If the query target's count exceeds the maximum value representable in the number of available bits, as reported by glGetQueryiv() with target set to the appropriate query target and pnameGL_QUERY_COUNTER_BITS, the count becomes undefined. An implementation may support 0 bits in its counter, in which case query results are always undefined and essentially useless. When GL_SAMPLE_BUFFERS is 0, the samples-passed counter of an occlusion query will increment once for each fragment that passes the depth test. When GL_SAMPLE_BUFFERS is 1, an implementation may either increment the samples-passed counter individually for each sample of a fragment that passes the depth test, or it may choose to increment the counter for all samples of a fragment if any one of them passes the depth test. The query targets GL_ANY_SAMPLES_PASSED, and GL_TIME_ELAPSED are availale only if the GL version is 3.3 or higher. The query target GL_ANY_SAMPLES_PASSED_CONSERVATIVE is available only of the GL version is 4.3 or higher. ERRORS
GL_INVALID_ENUM is generated if target is not one of the accepted tokens. GL_INVALID_OPERATION is generated if glBeginQuery is executed while a query object of the same target is already active. GL_INVALID_OPERATION is generated if glEndQuery() is executed when a query object of the same target is not active. GL_INVALID_OPERATION is generated if id is 0. GL_INVALID_OPERATION is generated if id is the name of an already active query object. GL_INVALID_OPERATION is generated if id refers to an existing query object whose type does not does not match target. SEE ALSO
glDeleteQueries(), glGenQueries(), glGetQueryiv(), glGetQueryObject(), glIsQuery() COPYRIGHT
Copyright (C) 2005 Addison-Wesley. Copyright (C) 2010-2012 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/. AUTHORS
opengl.org opengl.org 06/10/2014 GLBEGINQUERY(3G)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy