The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Print Problem in UNIX. Need to know the option to specify the print paper size ukarthik HP-UX 1 06-07-2007 09:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 06-22-2006
newlearner newlearner is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 8
Lightbulb How to print more than online using awk

Would you please help me on formatting the following lines of information.

Input file:
-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 0.000 [ one line only]
select emp_no, dept_no
from emp
where empname like 'Rob%'
;

-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 0.999 [ one line only]
select emp_no, dept_no
from dept
where deptname like 'IT%'
;

Output need to have all lines where server_elapsed >0.100 like below
server_elapsed=0.999 |select emp_no, dept_no from dept where deptname like 'IT%' ; [One line only]
  #2 (permalink)  
Old 06-22-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Code:
>cat inp
-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 0.000
select emp_no, dept_no
from emp
where empname like 'Rob%'
;

-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 0.999
select emp_no, dept_no
from dept
where deptname like 'IT%'
;

Code:
firststring=`awk -F"=" '/server_elapsed/ { if( $7 > 0.100 ) { print "server_elapsed="$7"|"} }' inp`
val=`awk -F"=" '/server_elapsed/ { if( $7 > 0.100 ) { print NR } }' inp`
echo $firststring`awk -F"=" '{ if(NR > '$val' && NR <= '$val' + 4) { printf $0" " } }' inp`
output
Code:
server_elapsed= 0.999 |select emp_no, dept_no from dept where deptname like 'IT%' ;
  #3 (permalink)  
Old 06-23-2006
newlearner newlearner is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 8
Thanks for your help madhan. It is working fine. But I found some lines with more feilds in the first line and $7 is not validating.

For this I modified the code to
firststring=`awk -F"server_elapsed = " '/server_elapsed/ { if( $2 > 0.100 ) { print "server_elapsed="$2"|"} }' tran.log`
and the above line is working fine.

But the issue with number lines in the select statement they are not constant i.e 4.

I am getting with more like 1 ....50.

Would u please suggest me how to deal with this.

Thanks for your kind reply.
  #4 (permalink)  
Old 06-26-2006
newlearner newlearner is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 8
How to print multiple lines

Thanks for your help on printing the input text matrixmadhan.

But I need help on multiple lines if they condition met.

-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 2.999
select emp_no, dept_no
from emp
where empname like 'Rob%'
;

-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 0.999
select emp_no, dept_no
from dept
where deptname like 'IT%'
;


As per the above input, there will be two output lines.

server_elapsed= 0.999 |select emp_no, dept_no from dept where deptname like 'IT%' ;
server_elapsed= 2.999 |select emp_no, dept_no from emp where empname like 'Rob%';

Would you please help me in printing.

I appreciate your kind reply.

Rgds,
AWK New Learner
  #5 (permalink)  
Old 06-28-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
you gave the input and output...

i am not clear with the requirement you request ..

could you please clarify ?

(i dont have good grasping skills)
  #6 (permalink)  
Old 06-28-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Quote:
Originally Posted by newlearner
Thanks for your help madhan. It is working fine. But I found some lines with more feilds in the first line and $7 is not validating.

For this I modified the code to
firststring=`awk -F"server_elapsed = " '/server_elapsed/ { if( $2 > 0.100 ) { print "server_elapsed="$2"|"} }' tran.log`
and the above line is working fine.

But the issue with number lines in the select statement they are not constant i.e 4.

I am getting with more like 1 ....50.

Would u please suggest me how to deal with this.

Thanks for your kind reply.
here it is,
i should have thought earlier
Code:
#! /usr/bin/ksh

firststring=`awk -F"=" '/server_elapsed/ { if( $7 > 0.100 ) { print   server_elapsed="$7"|"} }' inp`
val=`awk -F"=" '/server_elapsed/ { if( $7 > 0.100 ) { print NR } }' inp`
echo $firststring`awk -F"=" 'BEGIN{} { if(NR > '$val' && $0 !~ /^;/ ) { printf $0" " } } END{ printf ";" }' inp`

exit 0
  #7 (permalink)  
Old 06-28-2006
newlearner newlearner is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 8
Thanks for your help matrix.

I am getting the following error, would you please help me on this.

Syntax Error The source line is 1.
The error context is
BEGIN{} { if(NR > >>> 1 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
awk: 0602-540 There is a missing ) character.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0