LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-23-2014, 07:53 AM   #1
ihoward92
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Rep: Reputation: Disabled
How to convert binary file into text file in linux


Hi,

I am trying to run a fluid simulation in Scilab, creating a 2d velocity field. For this the simulation is being run using linux which creates a binary file of data. I need to convert this into a basic text file that you would use on windows notepad, the data when converted to a normal text file should show a matrix of numbers. Does anyone have any idea how this can be done? Cheers
 
Old 02-23-2014, 08:31 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
You will likely have to write a program that knows the format of the field data file, and prints in the format you want for windows.

Though why notepad I'm not sure - (not being familar with notepad) the file could be quite large...
 
Old 02-23-2014, 09:17 AM   #3
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Quote:
the simulation is being run using linux which creates a binary file of data
I'm not quite sure what you mean by "binary file of data"? What exact format is this "binary file" and what programs in linux are supposed to run it. Usually the program that runs the binary file should have an option of saving the data in a text file.
jdk
 
Old 02-23-2014, 09:47 AM   #4
ihoward92
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Here was the source code to dump the data into binary files, i need to instead of "write" read the binary file and convert it into a text file, will something like base64 work?
subroutine datadump
c
implicit none
include '../sttls.h'
include '../dcl.h'
c
integer*4 i,j,k,l
c
open (unit=2,status='unknown',file='results/y.dat',
> form='unformatted')
do i=1,nx
write(2) (((x(l,i,j,k),l=1,16),j=1,ny),k=1,nz)
write(2) ((fx(i,j,k),j=1,ny),k=1,nz)
write(2) ((fy(i,j,k),j=1,ny),k=1,nz)
write(2) ((fz(i,j,k),j=1,ny),k=1,nz)
write(2) ((c(1,i,j,k),j=1,ny),k=1,nz)
enddo
write(2) teta,nrev
close (unit=2)
end
 
Old 02-23-2014, 09:55 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
No.

And if you look at the data, it has varying sizes - ny, nz, and nk.

None of which are contained within the file... so the file itself is arbitrary.

Just converting it to a base64 representation won't make it readable by anything.

Now if the machine architectures are compatible (as in using IEEE floating point, and same endian form) then just moving the binary file is sufficient for some compatible program to read (maybe - not sure what Windows does for binary files).

What are you trying to do?
 
Old 02-23-2014, 10:10 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am curious, the original problem is worded such that because it was created in linux the file needs to be changed there to be read in Windows.

I put it to the OP, if the binary file had been created under Windows, how would you have converted the file then?
 
Old 02-24-2014, 09:19 AM   #7
ihoward92
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Basically i am running a simulation in linux which has about 20 sourcecode files. I am new to linux and dont really understand how the whole process works but i was told i need to get the binary data that the simulation produces and convert it into a text file that i have written a program for in Scilab to read the text file and produce a velocity vector graphic simulation. I have a couple of sourcecode files for dumping the data and writing the file. I also have a folder which contains various files which contains the binary data. Overall the text files should produce numerical matrices that Scilab can read. The problem is that when the simulation is running it takes timestamps of the simulation and creates a new file for the data so i have a bunch of files for each timestamp giving different data. A Folder called cs in linux has all the data in the folder which has various files named e.g 2426, 2427,2428 etc each in it has data at a particular time in the simulation in binary. Does that help? is there anymore information i could provide that would provide a more clear indication of the problem in terms of coding? Cheers
 
Old 02-24-2014, 09:53 AM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i am not familiar with scilab so sorry if this is off-base, but it seems like what you are trying to do would be similar to converting an .mp3 audio file into ascii-text. (i know whenever i passed in my matlab assignments the code and output was always text unless there were a few plots i needed to print out).

i know in the case of things like open-office or microsoft word there is an option to file -> save as -> 'text' that can be read in vi or notepad.exe (does scilab have a similar export feature ?

looks like you written a program that is supposed to convert certain values to ascii text. how big is the output, i dont know scilab but can you upload a dump of the output somewhere and list what you would want as the expected output.txt (i suspect something can be written in 'c' to parse it).


edit: maybe hexedit or od would help here ?

Last edited by schneidz; 02-24-2014 at 11:05 AM.
 
Old 02-24-2014, 10:17 AM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
So you wrote a program (or are using a program) that writes some random format binary file.

Then you wrote a program that reads in some random format ASCII file.

And now you need a program to convert the random format binary file into a random format ASCII file? Why didn't you just write your data parser to read the original binary files instead of some random ASCII format that doesn't exist? Why can't you modify the code that's writing the binary files so that it writes ASCII instead in the format you want?

This whole situation makes no sense to me. And it has nothing at all to do with Linux vs Windows.

I guess the main question is, why did you write your Scilab program so that it reads in ASCII files that don't exist rather than the binary files that do?


To answer the original question, "How to convert binary file into text file in linux" - you write a custom program to parse the binary file and write out the data in ASCII, same as you would in Windows.

Last edited by suicidaleggroll; 02-24-2014 at 10:29 AM.
 
Old 02-24-2014, 10:41 AM   #10
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
I don't think Linux or operating systems are your problem here.. Rather you need someone that's familiar to Scilab... Please stop involving operating systems here since they have nothing to do with your problem..

From what I gather.. You need to create your own program that reads that specific file format (which happens to be in a binary form) and convert it to plain text (it will need to even respect your pattern/format so it can be usable in your other Scilab program)... I can assure you that no one else can do this for you..
 
Old 02-24-2014, 03:15 PM   #11
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
I need to convert this into a basic text file that you would use on windows notepad,
that will be a problem
even a "copy/ paste " of this post i am writing on linux and reading it on MS's notepad
will be "fun"

you NEED !!!! to run "unix2dos " on it

but do your self a VERY BIG favor on windows
UNINSTALL NOTEPAD.EXE


and use say "SciTE" or the Scite based program "notepad++"

as to data from the scilab code you wrote
just hack your code to output as a ascii CSV
or
to output the binary data into a organized output
say a new line for every value
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How would I convert an arbitrary binary file into a Linux executable file? ootawata Programming 8 02-21-2010 11:21 PM
Linux Text File convert to Windows/Notepad Text File = Wrapped? backroger Linux - Software 4 01-18-2009 05:54 AM
How to convert binary text file from Windows marie@dk Linux - Software 2 10-12-2005 03:17 AM
convert text file to binary excel file ust Linux - General 2 11-23-2004 02:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration