The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert two column data into 8 columns NickC Shell Programming and Scripting 8 06-28-2008 12:19 PM
How to convert a single column into several rows and columns? ashton_smith UNIX for Dummies Questions & Answers 5 05-24-2008 05:44 PM
Single column to multiple columns in awk astroDave Shell Programming and Scripting 2 03-27-2008 10:00 PM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
Print last 4 columns (variable column #) Da_Duck UNIX for Dummies Questions & Answers 19 02-27-2004 10:33 AM

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

Join Date: Oct 2007
Posts: 4
single column to multiple columns

Hello,
I have a single column of data that I would like to cut/print (with awk or ...) into multiple columns at every empty row (or common character).
Input:
5.99123
5.94693
7.21383

5.95202
0.907935
5.99149

6.08427
0.975774
6.077

Output:
5.99123 5.95202 6.08427
5.94693 0.907935 0.975774
7.21383 5.99149 6.077

Any help is appreciated.
Al
  #2 (permalink)  
Old 12-05-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
don't really know what 'common character' is, but.....

Code:
nawk -v RS='' '$1=$1' myInputFile

  #3 (permalink)  
Old 12-05-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Might try this:

awk 'BEGIN{MAX=0}
/^$/{NR=0; next;}
NR > MAX{MAX=NR}
{A[NR]=A[NR] " " $1}
END{for (I=1;I<=MAX;I++) {print substr(A[I],2)}}'
  #4 (permalink)  
Old 12-05-2007
agibbs agibbs is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Thanks for the replies. Unfortunately, the nawk example prints each row (between empty rows) as a new column, not as a single column (of rows between empty rows). The awk example is not working for me either, it prints blank rows no numbers -- please detail, row by row, what is meant to happen.
  #5 (permalink)  
Old 12-05-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
ah, I see what you mean now....

nawk -f ag.awk myInputFile

ag.awk:

Code:
BEGIN {
  RS=""
}
{
  for(i=1; i<=NF; i++)
    a[i] = (i in a) ? a[i] OFS $i : $i
}
END {
  for(i=1; i in a; i++)
     print a[i]
}

  #6 (permalink)  
Old 12-05-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Perhaps use paste...
Code:
$ cat file1
5.99123
5.94693
7.21383

5.95202
0.907935
5.99149

6.08427
0.975774
6.077

$ paste -s -d '   \n' file1
5.99123 5.94693 7.21383
5.95202 0.907935 5.99149
6.08427 0.975774 6.077
$

  #7 (permalink)  
Old 12-05-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: 717
Hi.

With commands:

Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate split file on context=empty line, paste into columns.

set -o nounset
echo

debug=":"
debug="echo"

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash csplit paste

echo

FILE=${1-data1}

# Remove debris from previous runs.
rm -f xx*

echo
csplit -k -z $FILE '/^[         ]*$/'+1 '{*}'

echo
ls xx*

echo
echo " Output:"
paste -d" " xx*

exit 0

Producing:

Code:
% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
csplit (coreutils) 5.2.1
paste (coreutils) 5.2.1


25
26
23

xx00  xx01  xx02

 Output:
5.99123 5.95202 6.08427
5.94693 0.907935 0.975774
7.21383 5.99149 6.077

The blank line goes at the end of each segment. See man pages for details ... 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 07:00 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