Import ASCII 28 delimited text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Import ASCII 28 delimited text file
# 1  
Old 02-07-2014
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
# 2  
Old 02-07-2014
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.

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

to turn ascii 28's into ^'s for example.
# 3  
Old 02-07-2014
Thanks Corona688.

This worked for my requirement.

Thanks
This User Gave Thanks to aneeta13 For This Post:
# 4  
Old 02-07-2014
Longhand using builtins only:-
OSX 10.7.5, default bash terminal...
Code:
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~> _


Last edited by wisecracker; 02-08-2014 at 09:55 AM.. Reason: Change "read -p ''" to "read -d ''"...
# 5  
Old 02-08-2014
Quote:
Originally Posted by wisecracker
Longhand using builtins only:-
OSX 10.7.5, default bash terminal...
Code:
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 -p '' text < /tmp/ascii28.txt
AMIGA:barrywalker~> read -p '' 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:
Code:
unprintable=$(printf '\x1C')

instead of:
Code:
printf "\x1C" > /tmp/unprintable
read -p '' unprintable < /tmp/unprintable

and, why use:
Code:
read -p '' text < /tmp/ascii28.txt

instead of:
Code:
read text < /tmp/ascii28.txt

or, more safely:
Code:
read -r text < /tmp/ascii28.txt

Is there some reason to specify that bash should prompt with an empty string that I'm missing?
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 02-08-2014
If you are using bash syntax, you could also use:
Code:
unprintable=$'\x1C'


Last edited by Scrutinizer; 02-08-2014 at 06:36 AM..
# 7  
Old 02-08-2014
Hi Don...

;o)

First this code.
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.
Code:
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating data delimited by ASCII code 1

<Any suggestion how to create a file where the values are separated by ASCII code 1,with data extracted from a table using shell script The format is :/> <columnname1(binary1)columnvalue(binary1)columnname2(binary1)columnvalue(binary1)columnname3(binary1)columnvalue... 1st row/>... (6 Replies)
Discussion started by: dasun
6 Replies

2. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

3. Homework & Coursework Questions

ASCII comma-delimited

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi Guys, I am new on the scripting world and would like ask for help if you can. Here are my questions... (1 Reply)
Discussion started by: mahiwaga
1 Replies

4. Shell Programming and Scripting

How can I reorganize the text file content for DB import?

Dear Madam / Sir, My Boss need to reorganize :rolleyes: the text file ready for DB import, here show you the requirment and seems not difficult but how to make it by shell script or other programming language effectively. FILE1 : user1,location1,location2,locatoin3,seat1,seat2,seat3... (4 Replies)
Discussion started by: ckwong99
4 Replies

5. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

6. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

7. Programming

Reading a binary file in text or ASCII format

Hi All, Please suggest me how to read a binary file in text or ASCII format. thanks Nagendra (3 Replies)
Discussion started by: Nagendra
3 Replies

8. Shell Programming and Scripting

mbox ascii mail text file ?

Hi, I am using "fetchmail" and "procmail" combination to trigger a job based on an input mail.Using fetchmail, incoming mail is downloaded from the mailserver to the local host.Once the mail is flushed,procmail starts execution and thereby triggers the application script. In-between... (3 Replies)
Discussion started by: DILEEP410
3 Replies

9. Shell Programming and Scripting

Check whether a given file is in ASCII format and data is tab-delimited

Hi All, Please help me out with a script which checks whether a given file say abc.txt is in ASCII format and data is tab-delimited. If the condition doesn't satisfy then it should generate error code "100" for file not in ASCII format and "105" if it is not in tab-delimited format. If the... (9 Replies)
Discussion started by: Mandab
9 Replies

10. UNIX for Dummies Questions & Answers

Creating flat text file (ASCII)

Hi everybody. I need help and I hope someone is willing to help me out here. My wholesale company is currently moving to new software. The old software is running on a UNIX platform. We need to migrate data from the UNIX system, but our former software provider refuses to assist the data... (5 Replies)
Discussion started by: Wdonero
5 Replies
Login or Register to Ask a Question