The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to read file into variable aspect_p Shell Programming and Scripting 7 03-21-2008 08:12 AM
How to read the configuration file from shell script nishanth hampal Shell Programming and Scripting 7 02-26-2008 11:42 PM
Urgent: selecting unique specific content of a file using shell script jisha Shell Programming and Scripting 2 01-08-2008 04:45 AM
Read variable from file in a C shell script haouesse Shell Programming and Scripting 2 11-07-2006 05:34 AM
How to read specific lines in a bulk file using C file Programming rajan_ka1 High Level Programming 10 11-09-2005 11:29 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2005
Registered User
 

Join Date: Aug 2005
Posts: 3
Shell Script to read specific lines in a file

I have a file with contents as follows

Record 1: Rejected - Error on table "DWO"."P2G_CUST_EVENTS".
ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated

Record 5: Rejected - Error on table "DWO"."P2G_CUST_EVENTS".
ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated

Record 6: Rejected - Error on table "DWO"."P2G_CUST_EVENTS".
ORA-00256: integrity constraint (DWO.CUST_EVENTS_PK) violated

Record 7: Rejected - Error on table "DWO"."P2G_CUST_EVENTS".
ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated



Now I need to find the record numbers against the rows having unique constraints. The data is present in 2 seperate lines, where the record number is present in the frist line and the Oracle Error in the subsequent line
I need to get the values
as follows in a file

1
5
7

because these are the record numbers of the rows having unique constraint errors.

I would like to know how to do it in shell scripting.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-22-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,323
Try this code (test.tmp is the file that holds the records):
Code:
for i in $(grep -n unique test.tmp|cut -d: -f1)
do
i=$(($i-1))
sed -n "${i},${i}p" test.tmp|cut -d: -f1|cut -d" " -f2
done
Reply With Quote
  #3 (permalink)  
Old 08-22-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,226
Try...
Code:
awk 'BEGIN { FS = "[ :]" }
     $1 == "Record" { r = $2 }
     $1 == "ORA-00001" { print r }
    ' file1
Reply With Quote
  #4 (permalink)  
Old 08-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 3
Quote:
Originally Posted by blowtorch
Try this code (test.tmp is the file that holds the records):
Code:
for i in $(grep -n unique test.tmp|cut -d: -f1)
do
i=$(($i-1))
sed -n "${i},${i}p" test.tmp|cut -d: -f1|cut -d" " -f2
done
Thank you very much for the response the code is working, however, the time it is taking is a bit more.
Reply With Quote
  #5 (permalink)  
Old 08-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 3
Quote:
Originally Posted by Ygor
Try...
Code:
awk 'BEGIN { FS = "[ :]" }
     $1 == "Record" { r = $2 }
     $1 == "ORA-00001" { print r }
    ' file1
Thank you very much the code is working. Though I still need to improve on the performance, if you have any ideas to improve the performance do let me know.
Reply With Quote
  #6 (permalink)  
Old 08-22-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
maybe...
Code:
nawk 'BEGIN {
  FS=RS=""
}
$2 ~ /^ORA-00001/ { match($1,/[0-9][0-9]*:/); print substr($1, RSTART, RLENGTH-1)}' file1
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0