From column to table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting From column to table
# 1  
Old 12-02-2010
From column to table

Hi,
I have an ascii file containing information. This file is n x m lines.

Is there a way to generate an ascii file where the information is stored as n x m table instead? The m columns should be tab separated.
Thanks a lot,
Sarah
# 2  
Old 12-02-2010
Please give an example of desired input and output
R0H0N
# 3  
Old 12-02-2010
It's quite a long file (above 100000) but it is something like this:
Input:
Quote:
1.08E-04
2.47E-06
1.55E-06
1.38E-06
1.50E-06
1.22E-06
3.54E-06
1.87E-06
1.49E-06
3.21E-06
1.45E-06
3.91E-06
2.13E-06
6.60E-06
3.37E-06
5.96E-06
5.46E-06
1.54E-06
4.74E-06
1.41E-06
0.00E+00
1.81E-06
3.63E-06
1.39E-06
5.74E-06
2.16E-06
4.08E-06
0.00E+00
9.31E-07
2.26E-06
3.45E-06
1.52E-06
2.71E-06
2.92E-06
1.12E-06
4.55E-06
2.95E-06
2.34E-06
2.31E-06
2.51E-07
9.99E-06
5.69E-06
4.29E-06
1.59E-06
0.00E+00
0.00E+00
0.00E+00
0.00E+00
3.17E-06
Output:
Quote:
1.08E-04 1.45E-06 0.00E+00 3.45E-06 9.99E-06
2.47E-06 3.91E-06 1.81E-06 1.52E-06 5.69E-06
1.55E-06 2.13E-06 3.63E-06 2.71E-06 4.29E-06
1.38E-06 6.60E-06 1.39E-06 2.92E-06 1.59E-06
1.50E-06 3.37E-06 5.74E-06 1.12E-06 0.00E+00
1.22E-06 5.96E-06 2.16E-06 4.55E-06 0.00E+00
3.54E-06 5.46E-06 4.08E-06 2.95E-06 0.00E+00
1.87E-06 1.54E-06 0.00E+00 2.34E-06 0.00E+00
1.49E-06 4.74E-06 9.31E-07 2.31E-06 3.17E-06
3.21E-06 1.41E-06 2.26E-06 2.51E-07 0.00E+00
Thank you
# 4  
Old 12-02-2010
First of all make one directory and copy input file in it. Then go to that directory and perform following steps.

1.> Split the input file using split command in number of rows that you want.

Code:
split -l 50 inputFile        # for 50 rows


2.> remove input file from current directory.

3.> then use paste command to merge them.

Code:
paste `ls` > outputFile

This User Gave Thanks to For This Post:
R0H0N
# 5  
Old 12-02-2010
Have a look at this thread:
https://www.unix.com/shell-programmin...e-columns.html

Maybe danmero's code will feet your needs?
Code:
$ awk '{_=NR%10}_{a[_]=((a[_])?a[_]FS:x)$1;l=(_>l)?_:l}END{for(i=0;++i<=l;)print a[i]}' file
1.08E-04 1.45E-06 0.00E+00 3.45E-06 9.99E-06
2.47E-06 3.91E-06 1.81E-06 1.52E-06 5.69E-06
1.55E-06 2.13E-06 3.63E-06 2.71E-06 4.29E-06
1.38E-06 6.60E-06 1.39E-06 2.92E-06 1.59E-06
1.50E-06 3.37E-06 5.74E-06 1.12E-06 0.00E+00
1.22E-06 5.96E-06 2.16E-06 4.55E-06 0.00E+00
3.54E-06 5.46E-06 4.08E-06 2.95E-06 0.00E+00
1.87E-06 1.54E-06 0.00E+00 2.34E-06 0.00E+00
1.49E-06 4.74E-06 9.31E-07 2.31E-06 3.17E-06

# 6  
Old 12-02-2010
with paste command but not that versatile..
Code:
cat inputfile | paste - - - - > outfile

# 7  
Old 12-02-2010
In the example there is a column of number but it can be also text. The solution of R0H0N works even if it is a bit "clumsy".
Thank you,
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

2. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

3. Shell Programming and Scripting

Verification of file name with table column

I am trying to generate code 1. move entire list of file names with specific pattern(standard patterned name for example file name is <process>_<country>_<yymmdd>) in a directory to a variable 2. Use variable in netezza code to check file name exist in a table or not? for example: Employee... (1 Reply)
Discussion started by: JayDoshi
1 Replies

4. Shell Programming and Scripting

Construct 3 column table from one column list

Hi all! trying my best to parse a public site for information (ie fiscal year and turnover) about corporations. Doing this by having a file with business name and registration number (search key) the file bolag.txt currently looks like this Burgundy 556732-7217 AcademicSearch 556406-9879... (11 Replies)
Discussion started by: martindebruin
11 Replies

5. UNIX for Advanced & Expert Users

Data from table to column

Hi All, in bash I have a text file which is something like 7.96634E-07 1.0000 0.00000E+00 0.0000 0.00000E+00 0.0000 1.59327E-06 0.7071 2.23058E-05 0.1890 6.61207E-05 0.1098 1.13919E-04 0.0865 1.47377E-04 0.0747 .... .... 0.00000E+00 0.0000 0.00000E+00 0.0000 ... (6 Replies)
Discussion started by: f_o_555
6 Replies

6. UNIX for Dummies Questions & Answers

average of a column in a table

Hello, Is there a quick way to compute the average of a column data in a numerical tab delimeted file? Thanks, Gussi (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

7. Shell Programming and Scripting

To update a column in a table through shell script

Hi All, I need to write a shell script in UNIX that should accept booking number as an argument and update it with value "NULL" if the transaction date is greater than 2 years. Booking number and transaction_date are the two columns of the table table_booking. Something like this, through... (3 Replies)
Discussion started by: shilpa_acc
3 Replies

8. Shell Programming and Scripting

updating a column in a unix table for a particular row

Hi, I have the following requirement. I have a unix table as below progname par1 par2 par3 par4 PROG1 abc def 0012 ooo PROG2 wed xas 0100 xxx PROG3 kkk ppp 0004 ppp Different programs(ex:PROG1,PROG2..) accesses this table and update... (5 Replies)
Discussion started by: thanuman
5 Replies

9. Shell Programming and Scripting

file in to the column of the table

Hi I am ETL person. I have a table in Oracle having one of its column defined as BLOB where it can hold huge data. When i generate a file in DataStage and place it in a path. and i would like dump the file in to the column of the table having datatype as BLOB. (0 Replies)
Discussion started by: sant_leo
0 Replies
Login or Register to Ask a Question