grep entire statement not just line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep entire statement not just line
# 1  
Old 08-27-2008
grep entire statement not just line

(extract from SQL binlog file...)

# at 4960
#080801 14:35:31 server id 4 end_log_pos 195 Query thread_id=63121426 exec_time=0 error_code=0
use d_jds;
SET TIMESTAMP=1217581531;
UPDATE bid_details set bidding = 3170.37 ,deduction=if((3170.37 < 37.43),0,deduction)
where contractID= 'L03550';
# at 5155
#080801 14:35:31 server id 4 end_log_pos 5182 Xid = 917824715
COMMIT;

when I grep for table name for e.g. "bidding" from a (binlog) file, it returns only the first line. I want to return the entire sql statement that ends with ";" that can span through 2 or 3 lines.
Is it possible?
# 2  
Old 08-27-2008
If it's always three lines then some grep programs have an option -A 2 to show two lines of trailing context after the match. Or to print from the match up through the next line containing a semicolon,

Code:
sed -n "/bidding/,/;/p" file.log

# 3  
Old 08-27-2008
awk '/Search_String/,/;/' Filename

You have to give the "Search String and the Filename" as per your requirement
# 4  
Old 08-28-2008
Hi.

The utility cgrep handles this:
Code:
#!/bin/bash -

# @(#) s1       Demonstrate grep across lines.
# See: http://www.bell-labs.com/project/wwexptools/cgrep/

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) cgrep
set -o nounset
echo

FILE=${1-data1}

echo " Data file $FILE:"
cat $FILE

echo
echo " Results:"
cgrep -D +w ";" bidding $FILE

exit 0

Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
cgrep (local) - no version provided for ~/executable/cgrep.

 Data file data1:
# at 4960
#080801 14:35:31 server id 4 end_log_pos 195 Query thread_id=63121426 exec_time=0 error_code=0
use d_jds;
SET TIMESTAMP=1217581531;
UPDATE bid_details set bidding = 3170.37 ,deduction=if((3170.37 < 37.43),0,deduction)
where contractID= 'L03550';
# at 5155
#080801 14:35:31 server id 4 end_log_pos 5182 Xid = 917824715
COMMIT;

 Results:
UPDATE bid_details set bidding = 3170.37 ,deduction=if((3170.37 < 37.43),0,deduction)
where contractID= 'L03550';

Context patterns can be specified with "-w" and "+w", the latter being used here ... cheers, drl
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using the entire line with space in between

Hi Folks, I have a report data like the one seen below. FRUITS@NEW_ORANGE(1500 04/29) FRUITS@NEW_ORANGE(1500 05/04) FRUITS@NEW_ORANGE(1500 05/05) FRUITS@NEW_ORANGE(1500 05/07) FRUITS@NEW_ORANGE(1500 05/12) I need to use each of this lines separately in another for loop like the one... (2 Replies)
Discussion started by: jayadanabalan
2 Replies

2. Shell Programming and Scripting

Conditional grep command to search entire file

Let me give you a complete example what I am trying to achieve. 1. Below is the log file structure where I need 2,5 and 14th column of the logs after grepping through the linkId=1ddoic. Log file structure:- abc.com 20120829001415 127.0.0.1 app none11111 sas 0 0 N clk Mozilla/5.0... (3 Replies)
Discussion started by: kmajumder
3 Replies

3. Shell Programming and Scripting

awk if statement not printing entire field

I have an input that looks like this: chr1 mm9_knownGene utr3 3204563 3206102 0 - . gene_id "Xkr4"; transcript_id "uc007aeu.1"; chr1 mm9_knownGene utr3 4280927 4283061 0 - . gene_id "Rp1"; transcript_id "uc007aew.1"; chr1 mm9_knownGene ... (5 Replies)
Discussion started by: pbluescript
5 Replies

4. UNIX and Linux Applications

grep hogs entire cpu

How can grep hog your entire cpu? I am absolutely shocked by this. (11 Replies)
Discussion started by: cokedude
11 Replies

5. UNIX for Dummies Questions & Answers

Show the entire line using ps

Using the vanilla ps -ef I noticed that the CMD (or command) line gets cut off after 90 characters UID PID PPID C STIME TTY TIME CMD root 6020 3822 0 Jun 19 ? 0:01 ./webservd-wdog -r /export/opt/sows/61sp4 -d /export/opt/sows/61sp4/https-logse Googling... (4 Replies)
Discussion started by: SixSigma1978
4 Replies

6. UNIX for Advanced & Expert Users

grep for entire line from a log folder

As per my understanding below mentioned line of code finding a word 'boy' in $ACULOG... num_errors=`grep -i -e fail -e illegal -e exception -e "<E" -e boy $ACULOG | wc -l` if I'm not corerct, please correct me. How I can find entire line like "This is a boy" with something similar as above... (1 Reply)
Discussion started by: heyitsmeok
1 Replies

7. Shell Programming and Scripting

grep to find entire line ....

As per my understanding below mentioned line of code finding a word 'boy' in $ACULOG... num_errors=`grep -i -e fail -e illegal -e exception -e "<E" -e boy $ACULOG | wc -l` if I'm not corerct, please correct me. How I can find entire line like "This is a boy" with something similar as above... (1 Reply)
Discussion started by: heyitsmeok
1 Replies

8. Shell Programming and Scripting

Grep for a pattern and print entire record

Hi friends, This is my very first post on forum, so kindly excuse if my doubts are found too silly. I am trying to automate a piece of routine work and this is where I am stuck at the moment-I need to grep a particular ID through a file containing many records(which start with <LRECORD> and end... (6 Replies)
Discussion started by: faiz1985
6 Replies

9. UNIX for Dummies Questions & Answers

grep question: stop search from finding entire line

Sorry for the title, I really don't know how to word this question or what to even search for. I tried "grep one match", "grep 1 match", "stop grep" on both google and here and haven't found something that helps, so here I go: I have a file that's about 1.5 million lines long, every line looks... (3 Replies)
Discussion started by: rmoakler
3 Replies

10. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies
Login or Register to Ask a Question