Sponsored Content
Top Forums Shell Programming and Scripting Import ASCII 28 delimited text file Post 302887484 by Don Cragun on Saturday 8th of February 2014 01:44:56 AM
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:
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 09:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy