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
More than transposing! bulash UNIX Desktop for Dummies Questions & Answers 3 04-11-2008 05:20 PM
Transposing string unibboy Shell Programming and Scripting 3 02-13-2008 06:12 PM
Another transposing issue stevesmith Shell Programming and Scripting 14 09-16-2006 04:48 AM
file transposing mskcc Shell Programming and Scripting 24 08-04-2005 11:23 AM
transposing letters myscsa2004 Shell Programming and Scripting 4 05-12-2004 10:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-01-2008
vikas_kesarwani vikas_kesarwani is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 17
Question Transposing a file

i have a file as:

1
2
3
4
5

i want output as :

1 2 3 4 5

can anybody help on this??
  #2 (permalink)  
Old 09-01-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Cochin/Singapore
Posts: 515
Try this:

Code:
cat filename | xargs
  #3 (permalink)  
Old 09-01-2008
yogi_raj_143 yogi_raj_143 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 16
Some thing similar
+++++++
cat filename | paste -s -
+++++++
Or for more advance operations, I have awk script by some forum like this
+++++++
#! /bin/sh

## ------------------------------------------------------------
## -- Transpose a matrix:
## -- Assumes all lines have same number of fields
## --
## -- Usage:
## -- script <STDIN> ^D
## -- script <input file>
## -- cat <input file> | script
## ------------------------------------------------------------
exec awk '
BEGIN {
FS = ","
OFS = ","
}
NR == 1 {
n = NF
for (i = 1; i <= NF; i++)
row[i] = $i
next
}
{
if (NF > n)
n = NF
for (i = 1; i <= NF; i++)
row[i] = row[i] "," $i
}
END {
for (i = 1; i <= n; i++)
print row[i]
}' ${1+"$@"}
+++++++
This assumes "," as input file field seperator
  #4 (permalink)  
Old 09-02-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,311
Quote:
Originally Posted by dennis.jacob View Post
Try this:

Code:
cat filename | xargs

Why are you using cat?

Code:
xargs < filename
  #5 (permalink)  
Old 09-02-2008
vikas_kesarwani vikas_kesarwani is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 17
thnx a lot for ur nice suggestions ......
  #6 (permalink)  
Old 09-02-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Or:

Code:
echo $(<filename)
  #7 (permalink)  
Old 09-02-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,311
Quote:
Originally Posted by Annihilannic View Post
Or:

Code:
echo $(<filename)

Code:
$ printf "%s\n" 1 2 3 4 5 > filename
$ echo $(<filename)

$ echo $(cat < filename)
1 2 3 4 5
$
When posting non-standard solutions, please specify which shell you are using.
Sponsored Links
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 translation by Google.
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