How to get some data in the file?

Hi all,

I have a log file with the below data.
I want to get only the red colored data from log file.

Record ----: Rejected may varies from one file to another file.

Please help me how to get some data in the file

Record 4466: Discarded - failed all WHEN clauses.
Record 4467: Discarded - failed all WHEN clauses.
Record 1632: Rejected - Error on table NOR_DATA, column COMPANY_NUM.
 ORA-01722: invalid number
Record 1659: Rejected - Error on table NOR_DATA, column COMPANY_NUM
 ORA-01722: invalid number
  
Table NOR_DATA:
   40 Rows successfully loaded.
   2 Rows not loaded due to data errors.
   4425 Rows not loaded because all WHEN clauses were failed.
   0 Rows not loaded because all fields were null.
  
  
Space allocated for bind array:               40958016 bytes(7216 rows)
 Read   buffer bytes:40960000
  
 
Total logical records skipped:          0
Total logical records read:          4467
Total logical records rejected:         2
Total logical records discarded:     4425
 

Run began on Thu Jan 03 01:14:50 2013
Run ended on Thu Jan 03 01:14:50 2013

 
Elapsed time was:     00:00:00.39
CPU time was:         00:00:00.23

Do you want to get these red colored lines just because the status says "rejected"??

Yes, but the rejected lines may vary from file to file.

In short, you want to copy all the lines after the phrase "Rejected" occur, to a new file. Correct?

Need to include rejected phrase also in the new file.

You like all lines from first found Rejected to end of file?

awk '{if ($0~"Rejected") a=1}0 {print}a' infile

yes. Correct.

where to include file name like from file, to file

awk '{if ($0~"Rejected") a=1}0 {print}a' fromfile > tofile
1 Like

When i am using below commad

awk '{if ($0~"Rejected") a=1}0 {print}a' fromfile > tofile

I got the error like this

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

On Solaris < version 11 use /usr/xpg4/bin/awk rather than awk

Previously i used awk command. that is working fine.

---------- Post updated at 05:46 AM ---------- Previous update was at 05:36 AM ----------

Rejected is inbetween the line.

Record 1632: Rejected - Error on table NOR_DATA, column COMPANY_NUM.
 ORA-01722: invalid number

Is this code

awk '{if ($0~"Rejected") a=1}0 {print}a' fromfile > tofile 

works fine or not?

On Ubuntu this line does work fine.

It could be shortened a little:

awk '/Rejected/{p=1}p' file

or

awk '/Rejected/,0' file

or

sed -n '/Rejected/,$p' file

This I understand:

awk '/Rejected/{p=1}p' file

Since P is 0 , no line is printed before it find Rejected and sets p=1

But how does this work:

awk '/Rejected/,0' file

0 means the condition will always be always false, so the second part of the pattern range will become true before the end of the file, so it will print from the first pattern until the end of the file..

1 Like