Create multiple text file from a single text file on AIX


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Create multiple text file from a single text file on AIX

Hi

I need to create multiple text files from onc text file on AIX. The data of text files is as below:

**********************************************
**********************************************
DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:45:42 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB01.dbf
DBVERIFY - Verification complete
Total Pages Examined : 384000
Total Pages Processed (Data) : 381455
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 24
Total Pages Failing (Index): 0
Total Pages Processed (Other): 2490
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 31
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3586837817 (1390.3586837817)
**********************************************
DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 14:11:41 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB01.dbf
DBVERIFY - Verification complete
Total Pages Examined : 393216
Total Pages Processed (Data) : 334746
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 53
Total Pages Failing (Index): 0
Total Pages Processed (Other): 3149
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 55268
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3586837801 (1390.3586837801)
**********************************************
DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 14:38:21 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB01.dbf
DBVERIFY - Verification complete
Total Pages Examined : 256000
Total Pages Processed (Data) : 255029
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 944
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 27
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3586837818 (1390.3586837818)
DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 15:20:51 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB05.dbf
DBVERIFY - Verification complete
Total Pages Examined : 524288
Total Pages Processed (Data) : 103421
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 307
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 420560
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3583763263 (1390.3583763263)
DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:21:37 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB.dbf
DBVERIFY - Verification complete
Total Pages Examined : 384000
Total Pages Processed (Data) : 379513
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 64
Total Pages Failing (Index): 0
Total Pages Processed (Other): 4398
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 25
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3587072460 (1390.3587072460)
DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:29:20 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB.dbf
DBVERIFY - Verification complete
Total Pages Examined : 768000
Total Pages Processed (Data) : 0
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 763709
Total Pages Failing (Index): 0
Total Pages Processed (Other): 4284
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 7
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3583378933 (1390.3583378933)
DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB.dbf
Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/fblprod/RBH_INDEX02.dbf
DBVERIFY - Verification complete
Total Pages Examined : 1722235
Total Pages Processed (Data) : 0
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 1712365
Total Pages Failing (Index): 0
Total Pages Processed (Other): 9823
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 47
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3593464263 (1390.3593464263)


Requried Output
Script should generate different files depending on the

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB.dbf


GL_TAB01.dbf
GL_TAB05.dbf
GL_TAB.dbf

File should contain following data

DBVERIFY - Verification starting : FILE = /oradata/fblprod/GL_TAB.dbf
DBVERIFY - Verification complete
Total Pages Examined : 768000
Total Pages Processed (Data) : 0
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 763709
Total Pages Failing (Index): 0
Total Pages Processed (Other): 4284
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 7
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 3583378933 (1390.3583378933)

If any file occured multiple time then its all multiple entry should be placeded in one file.

I also want to named the text file same as the File Name i.e. GL_TAB

Before posting this thread I searched the forum but unable to find any thread in the regard


Regards,

Hassan
# 2  
Try this:

Code:
awk -F"[\./]" '/FILE =/{f=$(NF-1)}f{print > f}' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Try:

Code:
awk -F"/" ' { if ($0 ~ /^DBVERIFY - Verification starting/) fn=$NF;  print $0 >>"file_"fn;  }'  filename

# 4  
changed data to something random

Hi Franklin!

Thanks for your support: Its really works.

Would u pls explain how it works:

awk -F"[\./]" '/FILE =/{f=$(NF-1)}f{print > f}' file

what does NF-1 means?

I have another file that contains different type of data as below I tried to execute same but it generates only 1 file named as 11

awk -F"[\./]" '/TITLE OF ACCOUNT : /{f=$(NF-1)}f{print > f}' rba141_15828820.eod.txt


Code:
^[M^O^M
^M
^M
^M
^M
      TITLE OF ACCOUNT : MUHAMMAD SAMI                                                                        STATEMENT DATE   :  18/11/2009 00:18:07^M
      JONNIE DOE                                                                                           STATEMENT PERIOD :  01-NOV-09 - 30-NOV-09^M
      H#11 -A SR#04 MINA PARK NOC ROAD                                                                         A/C NO. TYPE/CCY :  0111111115293 012/GBP^M
      QUETA                                                                                                    PAGE             :   1^M
      081745389,036216697158^M
^M
^M
^M
      OPENING BALANCE AS OF     Nov 01, 2009                                                                                                               1.020^M
      -----------------------------------------------------------------------------------------------------------------------------------------------------------^M
       TRAN DT EFF DT    TRAN BR  TRANSACTION DESCRIPTION           CHEQUE/VOUCHER/ATM NO.            WITHDRAWAL                  DEPOSIT                BALANCE^M
^M
       ----------------------------------------------------------------------------------------------------------------------------------------------------------^M
^M
       ENDING BALANCE AS OF     Nov 30, 2009                                                                                                               1.020^M
       AVAILABLE BALANCE AS OF  Nov 30, 2009                                                                                                               1.020^M
^M
       TRANSACTION SUMMARY^M
       NUMBER OF TRANSACTIONS      0^M
^M
^M
^M
^M
^M
^M
^M
       *** AS PER SBP MANDATE PLEASE^M
       SUBMIT AN ATTESTED COPY OF YOUR^M
       CNIC IMMEDIATELY **^M
       ** FOR BANK'S PROFILE PLEASE^M
       VISIT OUR WEBSITE^M
       "WWW.MYBANK.COM"^M
^M
^M
^M
^M
^M
^M
^M
^M
^M
^M
^M
^M
^M
^M
                                                                                                                                               .^M
^L^M
^M
^M
^M
^M
      TITLE OF ACCOUNT : DOE AMIR                                                                             STATEMENT DATE   :  18/11/2009 00:18:07^M
      DON ANDY                                                                                                STATEMENT PERIOD :  01-NOV-09 - 30-NOV-09^M
      H #31,B-1 KH-E-CHANGEZ PH-6 DHA                                                                           A/C NO. TYPE/CCY :  021212115943 010/USD^M
      KARACHI                                                                                                   PAGE             :   1^M
      021-2245111 / 0333-1111878^M
^M
^M
^M
      OPENING BALANCE AS OF     Nov 01, 2009                                                                                                           3,737.000^M
      -----------------------------------------------------------------------------------------------------------------------------------------------------------^M
       TRAN DT EFF DT    TRAN BR  TRANSACTION DESCRIPTION           CHEQUE/VOUCHER/ATM NO.            WITHDRAWAL                  DEPOSIT                BALANCE^M
^M
       ----------------------------------------------------------------------------------------------------------------------------------------------------------^M
^M
       ENDING BALANCE AS OF     Nov 30, 2009                                                                                                           3,737.000^M
       AVAILABLE BALANCE AS OF  Nov 30, 2009                                                                                                             910.000^M
^M
       TRANSACTION SUMMARY^M
       NUMBER OF TRANSACTIONS      0^M
^M
^M
^M
^M
^M
^M
^M
       *** AS PER SBP MANDATE PLEASE^M
       SUBMIT AN ATTESTED COPY OF YOUR^M
       CNIC IMMEDIATELY **^M
       ** FOR BANK'S PROFILE PLEASE^M
       VISIT OUR WEBSITE^M
       "WWW.MYBANK.COM"^M

In the above data I need to generate the separate text for each different Title of Account and file name should be as A/C NO. TYPE/CCY: value.

you may find some spaces in A/C No. We may create the file name as the value in red color and bold font. or if we can remove the spaces between its value and named the file with same (for only file name not in the data).

Thats why I am asking if you can explain the command. The awk is totally new for me.

Regards,

Hassan

Last edited by Neo; 11-18-2009 at 07:46 PM..
# 5  
The presence of ^M typically shows that the file originates from a windows/dos platform and that was transferred without a conversion to a unix format (e.g. ascii option in ftp). There are many options to convert afterwards. You can for instance use
Code:
dos2unix infile outfile

-or-
Code:
tr -d '\r' < infile > outfile

# 6  
After conversion the format you can try this:

Code:
awk '/A\/C NO. TYPE\/CCY :/{f=$(NF-1)}f{print > f}' unixfile


Explanation of the first command:

Code:
awk -F"[\./]" '/FILE =/{f=$(NF-1)}f{print > f}' file

Quote:
-F"[\./]" -> fieldseparator is "." or "/"

/FILE =/{f=$(NF-1)} -> if the line containes "FILE =" then the filename (variable f) = penultimate field

(NF-1) -> NF is the number of fields, $(NF-1) is the penultimate field

f{print > f} -> if f is not null print the entire line to the file f
With the explanation you should be able to customize the code if it doesn't give the desired result.
This User Gave Thanks to Franklin52 For This Post:
# 7  
Quote:
Originally Posted by Franklin52
Code:
awk '/A\/C NO. TYPE\/CCY :/{f=$(NF-1)}f{print > f}' unixfile

.
Files generated with A/C No. as required, but the initial 2 lines of every statement missed in newly created text files. i.e.

TITLE OF ACCOUNT : MUHAMMAD RASHID STATEMENT DATE : 18/11/2009 00:18:07^M
MUHAMMAD RASHID STATEMENT PERIOD : 01-NOV-09 - 30-NOV-09^M

I tried to create the files as below

Code:
awk '/TITLE OF ACCOUNT ://A\/C NO. TYPE\/CCY :/{f=$(NF-1)}f{print > f}' rba141_15828820.eod.txt

it gave me following error: Smilie
Syntax Error The source line is 1.
The error context is
/TITLE OF ACCOUNT >>> ://A\ <<< /C NO. TYPE\/CCY :/{f=$(NF-1)}f{print > f}
awk: 0602-500 Quitting The source line is 1.

Actually I want to named the file as A/C Number while data should start from Title of Account.

Regards,

Hassan
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Create multiple files from single file based on row separator

Hello , Can anyone please help me to solve the below - Input.txt source table abc col1 char col2 number source table bcd col1 date col2 char output should be 2 files based on the row separator "source table" abc.txt col1 char (6 Replies)
Discussion started by: Pratik4891
6 Replies

3. UNIX for Dummies Questions & Answers

Pdftotext from multiple pdf files to a single text file

I have a directory having a number of pdf files. I want to convert all the files to text, stored in a single text file The following creates multiple text files ls *.pdf | xargs -n1 pdftotext (1 Reply)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

Split a text file into multiple text files?

I have a text file with entries like 1186 5556 90844 7873 7722 12 7890.6 78.52 6679 3455 9867 1127 5642 ..N so many records like this. I want to split this file into multiple files like cluster1.txt, cluster2.txt, cluster3.txt, ..... clusterN.txt. (4 Replies)
Discussion started by: sammy777
4 Replies

5. UNIX for Dummies Questions & Answers

Changing text in multiple files, but with different text for each file

Hello, I have a situation where I want to change a line of text in multiple files, but the problem is that I want to change the text to something unique for each file. For example, let's say I have five files named bob.txt, joe.txt, john.txt, tom.txt, and zach.txt. Each of these files has a... (5 Replies)
Discussion started by: Scatterbrain26
5 Replies

6. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

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

8. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

9. Shell Programming and Scripting

Need to remove multiple text from a single file

Dear all, I have a file which have let us say records from A-Z. Now I want to remove multiple letter from this file using single command.. let us say I want to remove A,F,K,Y,U,P,B,S,D. I can use grep -v command but for this case i need to rerun the file several time i wana avoid using... (3 Replies)
Discussion started by: jojo123
3 Replies

10. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies

Featured Tech Videos