The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - list to tables Lobaria Shell Programming and Scripting 10 04-24-2008 08:07 AM
extract data from html tables Streetrcr UNIX for Dummies Questions & Answers 8 03-20-2008 06:14 AM
Routing tables kingdbag UNIX for Dummies Questions & Answers 9 10-06-2006 08:01 PM
viewing tables itldp UNIX for Dummies Questions & Answers 2 12-17-2003 09:19 AM
PHP: list into tables perleo Shell Programming and Scripting 2 10-01-2003 09:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-13-2007
justthisguy justthisguy is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
Converting tables of row data into columns of tables

I am trying to transpose tables listed in the [Input] format into [Output] format. Any help would be greatly appreciated.

Input:
Code:
test_data_1              
1  2  90%
4  3  91%
5  4  90%
6  5  90%
9  6  90%

test_data_2              
3  5  92%
5  4  92%
7  3  93%
9  2  92%
1  1  92%
...
Output:
Code:
test_data_1           test_data_2       ...
1  2  90%             3  5  92%         ...
4  3  91%             5  4  92%         ...
5  4  90%             7  3  93%         ...
6  5  90%             9  2  92%         ...
9  6  90%             1  1  92%         ...
Thanks much,

Chris Larson
Just this guy.
  #2 (permalink)  
Old 07-13-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Code:
paste file1 file2 file3 ...
  #3 (permalink)  
Old 07-13-2007
justthisguy justthisguy is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
Reborg,

Thanks. I should have clarified that the input data resides in a single file.

Also, I'm not sure how paste is going to help place the tables into a columnar layout. What I'm looking for is a way to take a single file in the first format and end up with a file containing the date tables side by side [by side by side etc.].

In other words, the [Output] section is an example of what I would like the output file to look like.

Chris Larson
JustThisGuy
  #4 (permalink)  
Old 07-13-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Is that the actual format of the data and not a simplified version?
  #5 (permalink)  
Old 07-13-2007
justthisguy justthisguy is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
That's the actual format. There are occasional tables with 2 elements per line, rather than 3, as the example below, but other than that, it's just as I posted above.

Code:
test_data_9
2  95%
3  94%
4  91%
5  92%
6  93%
7  90%
  #6 (permalink)  
Old 07-13-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi.

Here is one approach:
Code:
#!/bin/sh

# @(#) s1       Demonstrate context splitting, pasting, adjusting columns.

set -o nounset
echo
echo "GNU bash $BASH_VERSION" >&2
csplit --version | head -1 >&2
echo

FILE=${1-data1}
csplit -k -z $FILE /^test_data/ "{*}"

echo
echo " Lines per file:"
wc -l xx*

echo
paste xx* |
column -s"      " -t
# Note: there is a TAB inside -s" ".

exit 0
which, on your data file (with extra line in data set 9) produces:
Code:
% ./s1

GNU bash 2.05b.0(1)-release
csplit (coreutils) 5.2.1

76
76
54

 Lines per file:
  6 xx00
  6 xx01
  7 xx02
 19 total

test_data_1                test_data_2                test_data_9
1  2  90%                  3  5  92%                  2  95%
4  3  91%                  5  4  92%                  3  94%
5  4  90%                  7  3  93%                  4  91%
6  5  90%                  9  2  92%                  5  92%
9  6  90%                  1  1  92%                  6  93%
7  90%
See man pages for details on the options ... cheers, drl
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0