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

Try this:

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

Try:

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

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

^[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

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

dos2unix infile outfile

-or-

tr -d '\r' < infile > outfile

After conversion the format you can try this:

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

Explanation of the first command:

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

With the explanation you should be able to customize the code if it doesn't give the desired result.

1 Like

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

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

it gave me following error: :o
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

Should be something like:

awk '/TITLE OF ACCOUNT :/{s=$0;getline; s=s RS $0;next}
/A\/C NO. TYPE\/CCY :/{f=$(NF-1)}f{print s > f;print > f}' file
1 Like

Another solution (assumes formfeed as data delimitor) :

awk '
FNR==1 || /\f/{ 
   memo = 1
}
/A\/C NO\. TYPE\/CCY/ {
   filename = $(NF-1);
   $0 = Text ORS $0;
   memo = 0;
   Text = "";
}
 memo { 
   Text = Text (memo ? ORS : "") $0 ;
}
! memo { 
  print > filename;
 }
' input_file

Jean-Pierre.

1 Like

Thru this the first 2 lines are printing after every line. i.e.

aigles code is generating right output.

Regards,

Hassan

Franklin52 code is true but need to be modified to the below to give the correct result.

Code:

gawk '/TITLE OF ACCOUNT :/{s=$0;getline; s=s RS $0;next}
/A\/C NO. TYPE\/CCY :/{f=$(NF-1) ; print s > f}f{print >> f}' file

you can use nawk gawk or /usr/xpg4/bin/awk

BR
:D:D:D:D:D

Thanks Ahmad for your correction. I did not mean that it was wrong, how can I say bcz he is the first one who replied me.

Any I make changes as per your suggestion i.e.

awk '/TITLE OF ACCOUNT :/{s=$0;getline; s=s RS $0;next}/A\/C NO. TYPE\/CCY :/{f=$(NF-1) ; print s > f}f{print >> f}' abc4.txt

and found correct result.

I also noticed that while using the code suggested by aigles is making little strange output, Put first 2 lines of a the single text file in every newly created file, and the original data of that account no is displaying in the end of every file. i.e.

==================1st New File =======================
TITLE OF ACCOUNT : MUHAMMAD NASIM STATEMENT DATE : 18/11/2009 00:18:07
MUHAMMAD NASIM STATEMENT PERIOD : 01-NOV-09 - 30-NOV-09
501 EMAN ANENUE SHAHRA-E-FARMA N A/C NO. TYPE/CCY : 01311111111182 010/USD
WEHARI PAGE : 1
091-495, 5130, 082318

  OPENING BALANCE AS OF     Nov 01, 2009                                                                                                             480.990
  \-----------------------------------------------------------------------------------------------------------------------------------------------------------
   TRAN DT EFF DT    TRAN BR  TRANSACTION DESCRIPTION           CHEQUE/VOUCHER/ATM NO.            WITHDRAWAL                  DEPOSIT                BALANCE

   \----------------------------------------------------------------------------------------------------------------------------------------------------------

   ENDING BALANCE AS OF     Nov 30, 2009                                                                                                             480.990
   AVAILABLE BALANCE AS OF  Nov 30, 2009                                                                                                             480.990

   TRANSACTION SUMMARY
   NUMBER OF TRANSACTIONS      0







   *** AS PER SBP MANDATE PLEASE
   SUBMIT AN ATTESTED COPY OF YOUR
   CNIC IMMEDIATELY \**
   ** FOR BANK'S PROFILE PLEASE
   VISIT OUR WEBSITE
   "WWW.MYBANK.COM"

==================2nd New File =======================
TITLE OF ACCOUNT : MUHAMMAD NASIM STATEMENT DATE : 18/11/2009 00:18:07
MUHAMMAD NASIM STATEMENT PERIOD : 01-NOV-09 - 30-NOV-09
H #39,B-1BAZ PH-9999996 BAHARAN A/C NO. TYPE/CCY : 01241111111143 010/USD
SIALKOT PAGE : 1
091-27 / 08878

  OPENING BALANCE AS OF     Nov 01, 2009                                                                                                           3,737.000
  \-----------------------------------------------------------------------------------------------------------------------------------------------------------
   TRAN DT EFF DT    TRAN BR  TRANSACTION DESCRIPTION           CHEQUE/VOUCHER/ATM NO.            WITHDRAWAL                  DEPOSIT                BALANCE

   \----------------------------------------------------------------------------------------------------------------------------------------------------------

   ENDING BALANCE AS OF     Nov 30, 2009                                                                                                           3,737.000
   AVAILABLE BALANCE AS OF  Nov 30, 2009                                                                                                             910.000

   TRANSACTION SUMMARY
   NUMBER OF TRANSACTIONS      0







   *** AS PER SBP MANDATE PLEASE
   SUBMIT AN ATTESTED COPY OF YOUR
   CNIC IMMEDIATELY \**
   ** FOR BANK'S PROFILE PLEASE
   VISIT OUR WEBSITE
   "WWW.MYBANK.COM"






  TITLE OF ACCOUNT : MUHAMMAD KHAN                                                                          STATEMENT DATE   :  18/11/2009 00:18:07
  MOHAMMAD KHAN                                                                                             STATEMENT PERIOD :  01-NOV-09 - 30-NOV-09

The red color text of 2nd new file must appeared in the start of this file but starting two lines of every new file displaying the first files' two lines.

Regards,

Hassan