[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

    Search the Q&A Archives

...possible to open & display records of Non-Text files...

<< Back to: comp.lang.awk FAQ

Question by Satheesh Kumar
Submitted on 8/4/2003
Related FAQ: comp.lang.awk FAQ
Rating: Not yet rated Rate this question: Vote
Is it possible to open & display records of Non-Text files using AWK? How?

Answer by obrienpx
Submitted on 8/21/2003
Rating: Not yet rated Rate this answer: Vote
I would be reluctant to say it is impossible but I do not know of any way.  In my opinion it goes against the philosophy of the language.  It is a (fairly) simple pattern matching language to manipulate text data in various ways.  Default input is line-by-line which does not, in  general, work for non-text files.

But it may be possible in some variant of the language.


Answer by Gus
Submitted on 8/24/2004
Rating: Not yet rated Rate this answer: Vote
As long as you don't mean "open" the file in the windows sense (i.e. open for edit), sure, you can use awk to translate non-printable characters (or all characters) into a text form.  For example,

  for (i=0; i<=255; i++)
  for (i=1; i<=length($a); i++)
    printf "%s ",trans(substr($0,i,1))

Converts all characters into the HTML "entities" used for unprintable characters.  A more selective building of trans will allow you to leave printable characters alone.

If you're working in a unix/linux environment, "od" might be a better choice.


Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.

Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.


FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.


<< Back to: comp.lang.awk FAQ

[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.