![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|
#3
|
||||
|
||||
|
Try...
Code:
awk 'BEGIN { FS = "[ :]" }
$1 == "Record" { r = $2 }
$1 == "ORA-00001" { print r }
' file1
|
|
#4
|
|||
|
|||
|
Quote:
|
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
||||
|
||||
|
maybe...
Code:
nawk 'BEGIN {
FS=RS=""
}
$2 ~ /^ORA-00001/ { match($1,/[0-9][0-9]*:/); print substr($1, RSTART, RLENGTH-1)}' file1
|
||||
| Google The UNIX and Linux Forums |