Divide data into separate files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Divide data into separate files
# 1  
Old 04-11-2012
Divide data into separate files

frnds:

i want to divide data on the behalf of dotted line and redirectd into new files

Code:
 )                       
-------------------------
 M-GET CONFIRMATION (    
-------------------------
 M-GET CONFIRMATION (    
     INVOKE IDENTIFIER

final data shuld be into 3 files ... file1 file2 file3

Last edited by methyl; 04-11-2012 at 07:32 AM.. Reason: please use code tags ; correct spelling of divide
# 2  
Old 04-11-2012
Please give us more clue. Expected input and output.
# 3  
Old 04-11-2012
input data mentioed above:

output shud be:
Code:
 )  -- shud be in file1                    
-------------------------
 M-GET CONFIRMATION (    shud be in file 2
-------------------------
 M-GET CONFIRMATION (     shud be in file3
     INVOKE IDENTIFIER

after every doted line data shud be redirected into a new file$

Last edited by methyl; 04-11-2012 at 09:09 AM.. Reason: please use code tags
# 4  
Old 04-11-2012
Hi

Code:
awk '!/^---/{print > "File"i;next}{i++}' i=1 inputfile

Guru.
# 5  
Old 04-12-2012
its not working ... i want on every repeation of dotted line it create a new file and redirect that paragraph into dat file
# 6  
Old 04-12-2012
Code:
 
awk 'BEGIN{i=1} {print $0 > "File_no"i;if (/^-----/) {++i}}' filename

# 7  
Old 04-12-2012
You can use csplit...
Code:
$ cat infile
)
-------------------------
 M-GET CONFIRMATION (
-------------------------
 M-GET CONFIRMATION (
     INVOKE IDENTIFIER

$ csplit --prefix='outfile' infile '/----------/' '{*}'
25
52
75

$ head outfile??
==> outfile00 <==
)

==> outfile01 <==
-------------------------
 M-GET CONFIRMATION (

==> outfile02 <==
-------------------------
 M-GET CONFIRMATION (
     INVOKE IDENTIFIER

...or if you don't want the line of dashes in the output files, then try awk...
Code:
$ awk '/----------/{close(f);i++;next}{f=sprintf("outfile%02d",i);print > f}' infile

$ head outfile??
==> outfile00 <==
)

==> outfile01 <==
 M-GET CONFIRMATION (

==> outfile02 <==
 M-GET CONFIRMATION (
     INVOKE IDENTIFIER

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Divide a numerical data column by a variable

Hello, I have two files, f1 and f2. f1 has 5 columns like so: a b c d 154 e f g h 365 ..... f2 has two columns, the first column contains the name of the above file and second column contains a constant which is to be used for division. e.g. file1 56 I want to divide the 5th... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

2. Shell Programming and Scripting

Divide an EBCDIC files into multiple files based on value at 45-46 bytes

Hi All, I do have an EBCDIC file sent from the z/os , this file has records with different record types in it, the type of record is identified by bytes 45-46 like value 12 has employee record value 14 has salaray record and etc.... we do now want to split the big ebcdic file into multiple... (3 Replies)
Discussion started by: okkadu
3 Replies

3. Shell Programming and Scripting

Divide data with specific column values into separate files

hello! i need a little help from you :) ... i need to split a file into separate files depending on two conditions using scripting. The file has no delimiters. The conditions are col 17 = "P" and col 81 = "*", this will go to one output file; col 17 = "R" and col 81 = " ". Here is an example. ... (3 Replies)
Discussion started by: chanclitas
3 Replies

4. UNIX for Dummies Questions & Answers

divide the file into multiple files based on the city name

Hi, I have a file abc.dat. It contains the fileds of empid, empname, empcity. each city contains 10 records. i want to create the city file and pass the same city records into the file. I don't know the city names. In unix using awk command how can we do? abc.dat: 1 john delhi 2... (2 Replies)
Discussion started by: raghukreddy.ab
2 Replies

5. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

6. Shell Programming and Scripting

Match two files and divide fields

I have two files that have the date field in common. I request your help with some script that divide each field value from file1 by the correspond field value of the file2 only when the field date is equal in both files. Thanks in advance ! This is a sample of the files file 1 12/16/2010,... (2 Replies)
Discussion started by: csierra
2 Replies

7. Shell Programming and Scripting

Divide large data files into smaller files

Hello everyone! I have 2 types of files in the following format: 1) *.fa >1234 ...some text... >2345 ...some text... >3456 ...some text... . . . . 2) *.info >1234 (7 Replies)
Discussion started by: ad23
7 Replies

8. Shell Programming and Scripting

Match two files and divide a field !

Hello, I have two files that have the date field as a common. I request your help with some script that divide the value of the file1 by the value in the file2 only when the field date are the same between both files and create a new text file. This is a sample of the files file1... (1 Reply)
Discussion started by: csierra
1 Replies

9. Shell Programming and Scripting

Using AWK to separate data from a large XML file into multiple files

I have a 500 MB XML file from a FileMaker database export, it's formatted horribly (no line breaks at all). The node structure is basically <FMPXMLRESULT> <METADATA> <FIELD att="............." id="..."/> </METADATA> <RESULTSET FOUND="1763457"> <ROW att="....." etc="...."> ... (16 Replies)
Discussion started by: JRy
16 Replies

10. Shell Programming and Scripting

divide a single file with different Weboffercodes into different files with each of o

Here is the format of my file; I do not have the delimiter in the file for the data to be separated. Each line in the file is in the following format. File contains the data of different WebOfferCodes Item Code | Account Number | Card Number | Source code | WebOfferCode 12digits | 10... (4 Replies)
Discussion started by: enigma_83
4 Replies
Login or Register to Ask a Question