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 09:12 AM
How to read the configuration file from shell script nishanth hampal Shell Programming and Scripting 7 02-27-2008 12:42 AM
Urgent: selecting unique specific content of a file using shell script jisha Shell Programming and Scripting 2 01-08-2008 05:45 AM
Read variable from file in a C shell script haouesse Shell Programming and Scripting 2 11-07-2006 06:34 AM
How to read specific lines in a bulk file using C file Programming rajan_ka1 High Level Programming 10 11-10-2005 12:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
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  
Old 08-22-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
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  
Old 08-22-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Try...
Code:
awk 'BEGIN { FS = "[ :]" }
     $1 == "Record" { r = $2 }
     $1 == "ORA-00001" { print r }
    ' file1
Reply With Quote
  #4  
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  
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  
Old 08-22-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,022
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 The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:17 AM.


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

Content Relevant URLs by vBSEO 3.2.0