Split binary file with pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split binary file with pattern
# 1  
Old 02-10-2010
Split binary file with pattern

Hello!

Have some problem with extract files from saved session.

File contains any kind of special/printable characters.

Code:
DATA NumberA DATA
DATA Begin
DATA1.1
DATA1.2 NumberB1 DATA1.3
DATA1.4
End DATA
DATA
DATA Begin
DATA2.1
DATA2.2 NumberB2 DATA2.3
DATA2.4
End DATA
DATA
...
...
DATA Begin
 DATAXXX.1
 DATAXXX.2 NumberBXXX DATAXXX.3
 DATAXXX.4
 End DATA
 DATA

output file names are NumberANemberB1, NumberANemberB2 ... NumberANemberBXXX

contents
Code:
Begin
DATA1.1
DATA1.2 NumberB1 DATA1.3
DATA1.4
End

Begin
 DATA2.1
 DATA2.2 NumberB2 DATA2.3
 DATA2.4
 End
...
....
Begin
  DATAXXX.1
  DATAXXX.2 NumberBXXX DATAXXX.3
  DATAXXX.4
  End

Could you please help suggest me a way to do this.

Thank you very much!

Last edited by Franklin52; 02-10-2010 at 09:55 AM.. Reason: Please use code tags!
# 2  
Old 02-10-2010
Try this:
Code:
awk '/Begin$/{print $2; p=1; next}
/End/{print $1; p=0}
p' file

# 3  
Old 02-10-2010
sorry, that i have posted not an exact question. there is no spaces in file. that's why i think awk isn't suitable...
# 4  
Old 02-11-2010
Quote:
Originally Posted by vvild
sorry, that i have posted not an exact question. there is no spaces in file. that's why i think awk isn't suitable...
So give the exact format of your input file and the desired output within code tags.
# 5  
Old 02-12-2010
looks like this, but i could send real input and output files

input file

Code:
strings_of_useless_data
useless_data/krg01003265584.keyuseless_data
strings_of_useless_data
useless_dataBegin
strings_of_usefull_data
usefull_data/Name/im2/usefull_data
strings_of_usefull_data
End useless_data
strings_of_useless_data
useless_dataBegin
strings_of_usefull_data
usefull_data/Name/im10/usefull_data
strings_of_usefull_data
End useless_data

output files
im002_krg01003265584.key

Code:
Begin
strings_of_usefull_data
usefull_data/Name/im2/usefull_data
strings_of_usefull_data
End

im010_krg01003265584.key
Code:
Begin
 strings_of_usefull_data
 usefull_data/Name/im10/usefull_data
 strings_of_usefull_data
 End

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Split one file to many based on pattern

Hello All, I have records in a file in a pattern A,B,B,B,B,K,A,B,B,K Is there any command or simple logic I can pull out records into multiple files based on A record? I want output as File1: A,B,B,B,B,K File2: A,B,B,K (9 Replies)
Discussion started by: deal1dealer
9 Replies

2. Shell Programming and Scripting

How to split a file based on pattern line number?

Hi i have requirement like below M <form_name> sdasadasdMklkM D ...... D ..... M form_name> sdasadasdMklkM D ...... D ..... D ...... D ..... M form_name> sdasadasdMklkM D ...... M form_name> sdasadasdMklkM i want split file based on line number by finding... (10 Replies)
Discussion started by: bhaskar v
10 Replies

3. UNIX for Dummies Questions & Answers

Split a huge 7 GB File Based on Pattern into 4 files

Hi, I have a Huge 7 GB file which has around 1 million records, i want to split this file into 4 files to contain around 250k messages each. Please help me as Split command cannot work here as it might miss tags.. Format of the file is as below <!--###### ###### START-->... (6 Replies)
Discussion started by: KishM
6 Replies

4. UNIX for Dummies Questions & Answers

Split binary file every occurrence of a group of characters

Hello I am new to scripts, codes, bash, terminal, etc. I apologize this my be very scattered because I frankly don't have any idea where to begin and I have had trouble sleeping lately. I have several 2GB files I wish to split. This Code 00 00 01 BA ** ** ** ** ** ** ** ** C3 F8 00 00 01 BB 00... (17 Replies)
Discussion started by: PatrickE
17 Replies

5. Shell Programming and Scripting

Split the file based on pattern

Hi , I have huge files around 400 mb, which has clob data and have diffeent scenarios: I am trying to pass scenario number as parameter and and get required modified file based on the scenario number and criteria. Scenario 1: file name : scenario_1.txt ... (2 Replies)
Discussion started by: sol_nov
2 Replies

6. Shell Programming and Scripting

Split a file based on pattern and size

Hello, I have a large file (2GB) that I would like to split based on pattern and size. I've used the following command to split the file (token is "HELLO") awk '/HELLO/{i++}{print > "file"i}' input.txt and the output is similar to the following (i included filesize in KB): 10 ... (2 Replies)
Discussion started by: jl487
2 Replies

7. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

8. Shell Programming and Scripting

Split a file based on a pattern

Dear all, I have a large file which is composed of 8000 frames, what i would like to do is split the file into 8000 single files names file.pdb.1, file.pdb.2 etc etc each frame in the large file is seperated by a "ENDMDL" flag so my thinking is to use this flag a a point to split the files... (4 Replies)
Discussion started by: Mish_99
4 Replies

9. Shell Programming and Scripting

Split a binary file into 2 basing on 2 delemiter string

Hi all, I have a binary file (orig.dat) and two special delimiter strings 'AAA' and 'BBB'. My binary file's content is as follow: <Data1.1>AAA<Data1.2>BBB <Data2.1>AAA<Data2.2>BBB ... <DataN.1>AAA<DataN.2>BBB DataX.Y might have any length, and contains any kind of special/printable... (1 Reply)
Discussion started by: Averell
1 Replies

10. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies
Login or Register to Ask a Question