Read an ascii as cell-tabulated form


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Read an ascii as cell-tabulated form
# 1  
Old 11-19-2010
Read an ascii as cell-tabulated form

Hi Guys,

I was wondering if it is possible to load a space-tabulated ascii as a "cell-tabulated form", something like excel. I have the following information:

Code:
tracl tracr fldr ep cdp cdpt nhs duse scalel scalco sx sy counit ns dt igi year day hour minute sec timbas
1 1 1 1 1 1 1 1 -1000 -1000 -431292246 123803010 2 4677 62 1 2007 268 21 47 53 4 
2 2 2 2 2 1 1 1 -1000 -1000 -431292246 123803010 2 4677 62 1 2007 268 21 47 53 4 
3 3 3 3 3 1 1 1 -1000 -1000 -431291562 123802776 2 4677 62 1 2007 268 21 48 1 4 
4 4 4 4 4 1 1 1 -1000 -1000 -431291562 123802776 2 4677 62 1 2007 268 21 48 1 4 
5 5 5 5 5 1 1 1 -1000 -1000 -431291520 123802757 2 4677 62 1 2007 268 21 48 2 4 
6 6 6 6 6 1 1 1 -1000 -1000 -431291484 123802740 2 4677 62 1 2007 268 21 48 2 4 
7 7 7 7 7 1 1 1 -1000 -1000 -431291484 123802740 2 4677 62 1 2007 268 21 48 2 4 
8 8 8 8 8 1 1 1 -1000 -1000 -431291442 123802722 2 4677 62 1 2007 268 21 48 3 4 
9 9 9 9 9 1 1 1 -1000 -1000 -431291442 123802722 2 4677 62 1 2007 268 21 48 3 4

I usually use nedit to show this file in a shell script. I don't know what tool could do what I want, I tried calling a spreadsheet for instance but didn't work.

I'd be very grateful if someone could suggest me a solution for this, thanks in advance.

Cheers,
# 2  
Old 11-19-2010
I don't understand. What is it that you want to do?
You want to process/massage the this data through the shell script somehow? You want to display it on the screen?
Elaborate please!
# 3  
Old 11-19-2010
Thanks for your answer. I just want to display it arranged by cells, like in the excel. So far I displayed it with nedit, ie. in the way I showed here.
# 4  
Old 11-19-2010
I don't think there's an Excel-like app in *NIX that comes out of the box...
You can convert your file into the HTML doc and display it in the browser....
# 5  
Old 11-20-2010
Thanks for the idea, however it isn't what I'm looking for, anyway, thanks again.
# 6  
Old 11-20-2010
Hi.

The perl code align is the best tool for column alignment I have seen. Here I used the first 10 columns of your input data as a demonstration. The first part shows the context on our systems, the last part is probably more of interest:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate align for column presentation, display.
# source for perl code "align": http://freshmeat.net/projects/align

# Section 1, setup, pre-solution.
# Infrastructure details, environment, commands for forum posts. 
# Uncomment export command to test script as external user.
# export PATH="/usr/local/bin:/usr/bin:/bin"
set +o nounset
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
C=$HOME/bin/context && [ -f $C ] && . $C align
set -o nounset
pe

FILE=${1-data1}

# Create short version of data file.

cut -f1-10 -d" " data0 > $FILE

# Section 2, display input file.
# Display sample of data file, with head & tail as a last resort.
pe " || start [ first:middle:last ]"
specimen $FILE \
|| { pe "(head/tail)"; head -n 5 $FILE; pe " ||"; tail -n 5 $FILE; }
pe " || end"

# Section 3, solution.
pl " Results:"
align $FILE

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 (lenny) 
GNU bash 3.2.39
align 1.7.0

 || start [ first:middle:last ]
Whole: 5:0:5 of 10 lines in file "data1"
tracl tracr fldr ep cdp cdpt nhs duse scalel scalco
1 1 1 1 1 1 1 1 -1000 -1000
2 2 2 2 2 1 1 1 -1000 -1000
3 3 3 3 3 1 1 1 -1000 -1000
4 4 4 4 4 1 1 1 -1000 -1000
5 5 5 5 5 1 1 1 -1000 -1000
6 6 6 6 6 1 1 1 -1000 -1000
7 7 7 7 7 1 1 1 -1000 -1000
8 8 8 8 8 1 1 1 -1000 -1000
9 9 9 9 9 1 1 1 -1000 -1000
 || end

-----
 Results:
tracl tracr fldr ep cdp cdpt nhs duse scalel scalco
1     1     1    1  1   1    1   1    -1000  -1000
2     2     2    2  2   1    1   1    -1000  -1000
3     3     3    3  3   1    1   1    -1000  -1000
4     4     4    4  4   1    1   1    -1000  -1000
5     5     5    5  5   1    1   1    -1000  -1000
6     6     6    6  6   1    1   1    -1000  -1000
7     7     7    7  7   1    1   1    -1000  -1000
8     8     8    8  8   1    1   1    -1000  -1000
9     9     9    9  9   1    1   1    -1000  -1000

The data are aligned, the default is "automatic", but options are available to force alignment to left, right, center, decimal, and much more.

See the URL noted the script listing for the source to align.

Best wishes ... cheers, drl
# 7  
Old 11-20-2010
Wow! it works perfectly dude!, many thanks for your help drl.

Interesting, I found a web site with a perl executable, I also installed it and works perfectly, here is the link:

Code:
http://www.cs.indiana.edu/~kinzler/align/

I don't know if it is the same, but it can also work if you needed.

Thanks again,

Cheers,

Gery
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies

2. Programming

How to read extended ASCII characters from stdin?

Hi, I want to read extended ASCII characters from keyboard using c language on unix/linux. How to read extended characters from keyboard or by copy-paste in terminal irrespective of locale set in the system. I want to read the input characters from keyboard, store it in an array or some local... (3 Replies)
Discussion started by: sanzee007
3 Replies

3. Shell Programming and Scripting

Script to read command line input and change it to some form

Hi, I want to write a small code in which script changes command line input to some form. Example script.sh a1 a2 a3 a4 ..... output should be "a1|a2|a3|....." Number of inputs in command line can be any variable (2 Replies)
Discussion started by: Raza Ali
2 Replies

4. Shell Programming and Scripting

How to read and append certain files form directory

Hi ,i have a question ,if I am in sertain directory and I have 4 files *.c how can I read and append this files in file backup.bac Thanks find ./ -name "*.csh" | wc -l (2 Replies)
Discussion started by: lio123
2 Replies

5. Shell Programming and Scripting

How to read one character form each line of the file?

Hi, Maybe this iscorrect forum for my question... I should read one character at a fixed position from each line of the file. So how ??? should be substituted in the code below: while read line ; do single_char=`???` echo "$single_char" done < $input_file OK...I did get an... (0 Replies)
Discussion started by: arsii
0 Replies

6. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

7. HP-UX

how to read ascii file in HP-UX

Hello All, I need to read the data inside one file who's format is ascii text. I got the file format when I use file command on the file. file <filename> filename ascii text please help me on this. Thanks (8 Replies)
Discussion started by: gyanusoni
8 Replies

8. Shell Programming and Scripting

Creating a tabulated file from content of 2 or more files

Hi all I need specific fields from a file to be tabulated into a single file. I have a file with the following :- FIELD1 InfoA FIELD2 InfoB FILED3 InfoC FIELD1 InfoD FIELD2 InfoE FIELD3 InfoF The output... (2 Replies)
Discussion started by: jhansrod
2 Replies

9. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies
Login or Register to Ask a Question