Import ASCII 28 delimited text file

I have an ASCII 28 delimited text file(non-printable delimiter) with 4 columns along with the header.I need to open this text file in Excel or any other tool to view each column content.

Please help..

Thanks

Excel really hates nonprinting characters as separators... Even if you manage to get one of them into the clipboard, it refuses to let you paste it as a custom separator. If there are any characters you know your file doesn't contain, you can translate them into something usable.

tr '\034' '^' < inputfile > outputfile

to turn ascii 28's into ^'s for example.

Thanks Corona688.

This worked for my requirement.

Thanks

1 Like

Longhand using builtins only:-
OSX 10.7.5, default bash terminal...

Last login: Fri Feb  7 21:34:30 on ttys000
AMIGA:barrywalker~> # Create a file with ASCII 28 in it...
AMIGA:barrywalker~> printf "Barry\x1CWalker\x1CG0LCU\x1C" > /tmp/ascii28.txt
AMIGA:barrywalker~> # Check it has 19 characters...
AMIGA:barrywalker~> hexdump -C < /tmp/ascii28.txt
00000000  42 61 72 72 79 1c 57 61  6c 6b 65 72 1c 47 30 4c  |Barry.Walker.G0L|
00000010  43 55 1c                                          |CU.|
00000013
AMIGA:barrywalker~> # Now create a file with ASCII 28 only...
AMIGA:barrywalker~> printf "\x1C" > /tmp/unprintable
AMIGA:barrywalker~> # Read in both files...
AMIGA:barrywalker~> read -d '' text < /tmp/ascii28.txt
AMIGA:barrywalker~> read -d '' unprintable < /tmp/unprintable
AMIGA:barrywalker~> # This is the working part.
AMIGA:barrywalker~> text=$(printf "${text//$unprintable/,}")
AMIGA:barrywalker~> echo "$text"
Barry,Walker,G0LCU,
AMIGA:barrywalker~> # Done! Comma separated variable now... ;o)
AMIGA:barrywalker~> _

Interesting...

Why not use:

unprintable=$(printf '\x1C')

instead of:

printf "\x1C" > /tmp/unprintable
read -p '' unprintable < /tmp/unprintable

and, why use:

read -p '' text < /tmp/ascii28.txt

instead of:

read text < /tmp/ascii28.txt

or, more safely:

read -r text < /tmp/ascii28.txt

Is there some reason to specify that bash should prompt with an empty string that I'm missing?

1 Like

If you are using bash syntax, you could also use:

unprintable=$'\x1C'

Hi Don...

;o)

First this code.

unprintable=$(printf '\x1C')

I did except that I always save odd unprintables to a drawer of my choice and had never
seen that one so I used that method. It stems from AMIGA CLI shell scripting, boy is that
difficult and limited, as I could create a strange character without using the SET command.
I won't go any further with this part as is it not relevant to UNIX scripting.

Secondly.

read -p '' text < /tmp/ascii28.txt

DRAT! That must be __dyslexia__ setting in, "-p" should be "-d", not a prompt...
I must admit I did use read on its own but thought it better that "\n"
should be taken into account...

Thanks for pointing out my error...