Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA249      CA318      CA425      CA651

w2mind.computing.dcu.ie      w2mind.org


Binary v. Text



Machine-readable data - from binary to text

Traditionally, program data would be in very efficient binary format:
 (2-byte-number)(4-byte-number)(1-byte-character)(2-byte-number)....
Program needs to know structure of the file to display it. Otherwise it doesn't know where to put boundaries - might display:
 (4-byte-no)(1-byte-char)(2-byte-no)(4-byte-no)....
There has been a trend more recently towards program data that humans can read in a text editor:
 (1-byte-character)(1-byte-character)(1-byte-character)....
which displays characters that express the contents. - html, xml, and (sort of) ps, tex



Text format is less efficient, but easier to work with

To store a 2 byte short integer in a file:


To edit the data:


"Human readable" machine data

With the readable format, an expert human can debug, tweak the data in a simple text editor, if they know what they are doing.

It is a much less efficient format - might take 16 1-byte characters to display the 2-byte-number - and this is why binary was so popular in the past. But can think about adopting such schemes now because machines getting more powerful, disk space bigger, bandwidth better than used to be.

HTML showed it could be done. XML is now taking idea one step further.
"Like HTML, XML files are text files that people shouldn't have to read, but may when the need arises."



Secret-format binary

Especially hard to work with are secret binary formats like Microsoft Word (before Word 2007), where you have to use somebody else's application to modify the data. If you use Microsoft Word .doc, you do not have access to the raw data of your document file. You cannot grep it at the command line. You cannot easily write scripts and small utilities to manipulate your documents yourself (e.g. search utilities). Instead you have to point and click inside other people's menus. This is the main reason why I never used Microsoft Word.




Scripting Word (and other Office)

It is possible, but hard, to write scripts to process Office files.

Q. Say you have 1,000 MS Word .doc (pre-2007) documents on disk. How do you search for a string in them? You can't do:
grep string *doc

  1. The default search in Windows Explorer can search for strings in Word files, but only returns the list of files that match, not the detailed output that grep returns.
    Q. Can Windows Explorer search be called from a DOS script? (Would need to return text output list of files.)

  2. Desktop search programs will pre-index your files and search them with a GUI or Web interface.
    Some can search Word files.
    Some can be called through a programming API.
    Q. Can any of these be called from a DOS script like grep?
    1. Google Desktop
    2. Windows Search

  3. You can use VBScript.


Q. Say you have 1,000 MS Word documents on disk. How do you go through them, changing string S1 everywhere it occurs into string S2?
This is easy (a few lines of code) if you have text formats, UNIX and shell scripts (grep and sed).

  1. You can use VBScript.


Q. For all the above, do I have to use Windows? What if I want to copy my 1,000 Word files to UNIX, where I normally work. Can I manipulate them there on UNIX? Or do I have to use Windows?

Q. Can you script access to online Office applications like Google Docs?
  1. Google Apps Script - scripting access to applications in the Google Apps family.


The end of Office secret format

The end of Office secret format - Office 2007 on


Feeds      HumphrysFamilyTree.com

Bookmark and Share           On Internet since 1987.