Create multiple text file from a single text file on AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create multiple text file from a single text file on AIX
# 8  
Old 11-18-2009
Should be something like:
Code:
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

This User Gave Thanks to Franklin52 For This Post:
# 9  
Old 11-18-2009
Another solution (assumes formfeed as data delimitor) :
Code:
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.

Last edited by aigles; 11-19-2009 at 03:19 AM.. Reason: Auto-increment of variable memo not needed + Re-init text variable
This User Gave Thanks to aigles For This Post:
# 10  
Old 11-18-2009
Quote:
Originally Posted by Franklin52
Should be something like:
Code:
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


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


aigles code is generating right output.

Regards,

Hassan

Last edited by lodhi1978; 11-18-2009 at 01:10 PM..
# 11  
Old 11-18-2009
Quote:
Originally Posted by lodhi1978
Thru this the first 2 lines are printing after every line. i.e.

TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
H# B-310 BLOCK-6 GULSHAN E IQBAL A/C NO. TYPE/CCY : 02310120000491 012/GBP
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
NEAR DISCO BAKRY KARACHI PAGE : 1
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
0215622001/0214979126/ 03212222661
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI STATEENT PERIOD : 01-NOV-09 - 30-NOV-09
OPENING BALANCE AS OF Nov 01, 2009 50.000
TITLE OF ACCOUNT : SYED HAIDER RAZA NAQVI STATEENT DATE : 18/11/2009 00:18:07
SYED HAIDER RAZA NAQVI

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:

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
SmilieSmilieSmilieSmilieSmilie
# 12  
Old 11-19-2009
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.
Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question