|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi to everyone
, i have a challenge right now in python that for now needs a bit of help in one part of the c0de.The task is create a new file with the name of the file defined by the ASCII content between the 3 byte and the 16 byte that is parsed from the binary file, the file is over 20 Mb i need to create a file for each record ( each record contains the len of 820 ), so right now i know how to read it and do something with it, like : Code:
Now the problem is , how do i get the name file that i want that is the string between the 2 byte and the 16 byte and how to save every 820 bytes to a new file like : Code:
#attention noob code coming for quick understading i have a for loop for #example not for use i have to use it for the each 820 bytes new file
#with the read of the 820 bytes on the new file and save it and go for the
#next 820 bytes and so on until the end of the file.
for f.read(820) in file:
if f.read() = 820:
a = f.read()
b = open("Iam_from_2_to_16_byte_string", w)
b.write(a)
b.close---------- Post updated 30-11-12 at 10:26 AM ---------- Previous update was 29-11-12 at 10:42 AM ---------- here is the solution : Code:
n = 820
with open('/home/drdos/work/file.PDA', "rb") as f:
while True:
data = f.read(n)
if not data:
break
filename = str(data[16:32])
x = open(filename, 'wb').write(data) |
| Sponsored Links | ||
|
![]() |
| Tags |
| binaries, parse lines onto new file, python |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read multiple files, parse data and append to a file | empyrean | Shell Programming and Scripting | 8 | 09-27-2012 05:50 PM |
| [Solved] Help to parse csv file with shell script | Grhyll | UNIX for Dummies Questions & Answers | 4 | 01-19-2012 09:45 AM |
| Help w/ script to read file and parse log message | shyork2001 | Shell Programming and Scripting | 2 | 04-06-2010 10:02 AM |
| Bash Script to read a file and parse each record | 3vilwyatt | Shell Programming and Scripting | 8 | 02-25-2010 01:04 AM |
| How to read and parse the content of csv file containing # as delimeter into fields using Bash? | barani75 | Shell Programming and Scripting | 4 | 02-22-2010 09:28 AM |
|
|