Need help in writing a script to create a new text file with specific data from existing two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in writing a script to create a new text file with specific data from existing two files
# 1  
Old 08-05-2010
Error Need help in writing a script to create a new text file with specific data from existing two files

Hi,

I have two text files. Need to create a third text file extracting specific data from first two existing files..

Text File 1: Format contains:


SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010

some text ............so on...and somwhere text like:
Record 1: Rejected - Error on table STAGE_DEN_CLM_HDR, column PAT_BRTH_DT.ORA-01861: literal does not match format string
......
......
Record 43: Rejected - Error on table STAGE_GEN_CLM_HDR, column PAT_BRTH_DT ORA-01861: literal does not match format string.

Text 2: Format contains:
214 ....0100119400831FSUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
214....010011940789546SUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Text 3: should contain like this.

All the Text 2 information should come in Text file3. Alsoo condition is>

I should get all the record errors in Text file 1 should appear in Text file 3.
Format should be like:
214 ....0100119400831FSUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Rejected - Error on table STAGE_DEN_CLM_HDR, column PAT_BRTH_DT.ORA-01861: literal does not match format string
214....010011940789546SUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Rejected - Error on table STAGE_GEN_CLM_HDR, column PAT_BRTH_DT ORA-01861: literal does not match format string.

This should work for any number of record errors in text 1.

Note: a)In Text file 2, All records start with 214 and ends with XXXXX...
b) In Text File 1, Record # is the word followed by error in record.

Request is to create a Text file3 with record failures.

Please help me on this. Hope i get some help today.

Thanks and Regards,
Shashi.

# 2  
Old 08-06-2010
would this work for you?

Code:
$ cat 1
SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010
 
some text ............so on...and somwhere text like:
Record 1: Rejected - Error on table STAGE_DEN_CLM_HDR, column PAT_BRTH_DT.ORA-01861: literal does not match format string
......
......
Record 43: Rejected - Error on table STAGE_GEN_CLM_HDR, column PAT_BRTH_DT ORA-01861: literal does not match format string.
 
 
$ 
$ 
$ 
$ cat 2
214 ....0100119400831FSUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
214....010011940789546SUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$ 
$ 
$ 
$ ksh f
214 ....0100119400831FSUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Record 1: Rejected - Error on table STAGE_DEN_CLM_HDR, column PAT_BRTH_DT.ORA-01861: literal does not match format string
214....010011940789546SUBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Record 43: Rejected - Error on table STAGE_GEN_CLM_HDR, column PAT_BRTH_DT ORA-01861: literal does not match format string.
$ 
$ 
$ 
$ cat f
exec 4<2
grep "^Record" 1 | while read r1
do
 read r2 <&4
 echo "$r2"
 echo "$r1"
done 
4<&-
 
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python DictWriter header - not writing in first line of existing file

Hello I am facing a very unique problem and not able to understand why. I have written a function which will check header of the file. If header is present good else it will write the header on top def writeHeaderOutputCSV(fileName): # See if the file exist already try: ... (0 Replies)
Discussion started by: radioactive9
0 Replies

2. UNIX for Beginners Questions & Answers

Create file based on data from two other files

I have looked through several threads regarding merging files with awk and attempted using join however have been unsuccessful likely as I do not fully understand awk. What I am attempting is to take a csv file which could be between 1 and 15,000 lines with 5 colums and another csv file that will... (4 Replies)
Discussion started by: cdubu2
4 Replies

3. Shell Programming and Scripting

How to read all data after a specific string from a text file ?

Hi, I have a file(input.txt) and trying to format as output.txt. See the attached file format. Note: This is a windows file (DOS format) and the commands are also going to execute on windows. Basically I am trying to capture all the data in between Local Group Memberships and Global Group... (10 Replies)
Discussion started by: Monoj2014
10 Replies

4. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

5. Shell Programming and Scripting

Create a report for client with a text data file

Hi, I am an amateur bash scriptwriter and I need to write a script which creates a report in a formatted, easy to read table-like that is displayed to standard output. The script has to export the followings: Process ID,User Name, Command Name,Priority..... Now I have a file that I can see all... (3 Replies)
Discussion started by: bashily
3 Replies

6. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

Hello everyone, I work under Ubuntu 11.10 (c-shell) I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment. I will show you an example: - On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Discussion started by: tenteyu
1 Replies

7. Shell Programming and Scripting

writing data in a text file at particular line

I need to write value of variable $version at a particular line in a text file. Line number is determined by another variable &line......I don't know how to do it in shell script ... (2 Replies)
Discussion started by: punitpa
2 Replies

8. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

9. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

10. Shell Programming and Scripting

help for a perl script - writing to a data file

Hi, Here is my problem.. i have 2 files (file1, file2).. i have wrote the last two lines and first 4 lines of "file2" into two different variables .. say.. my $firstrec = `head -4 $file2`; my $lastrec = `tail -2 $file2`; and i write the rest of the file2 to a tmpfile and cat it with head... (2 Replies)
Discussion started by: meghana
2 Replies
Login or Register to Ask a Question