Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

How do i do the vertical to horizontal??

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-01-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 19 February 2015, 9:04 PM EST
Location: Bangalore
Posts: 119
Thanks: 26
Thanked 2 Times in 2 Posts
How do i do the vertical to horizontal??


Code:
Code:
51009

8746

8912

17986

20315

24998

5368

38934

7805

8566

9993

14998

24996

5318

35254

5747

5999

7000

15000

25000

0

I want the above o/p to be in row wise...
every row shul hav 7 colmuns oly...
Sponsored Links
    #2  
Old Unix and Linux 03-01-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 25 May 2015, 11:35 PM EDT
Location: Amsterdam
Posts: 10,211
Thanks: 333
Thanked 2,694 Times in 2,410 Posts
How about:

Code:
xargs -n7 < file

The Following 3 Users Say Thank You to Scrutinizer For This Useful Post:
panyam (03-01-2013), RavinderSingh13 (11-22-2013), Yoda (03-01-2013)
Sponsored Links
    #3  
Old Unix and Linux 03-01-2013
panyam panyam is offline Forum Advisor  
Registered User
 
Join Date: Sep 2008
Last Activity: 8 December 2014, 6:40 AM EST
Posts: 1,159
Thanks: 20
Thanked 105 Times in 100 Posts

Code:
sed '/^$/d' file |   awk 'NR%7!=0 {a=a>0?a OFS $1:$1;next} { print a OFS $1;a=""}' OFS=","

    #4  
Old Unix and Linux 03-01-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 25 May 2015, 11:35 PM EDT
Location: Amsterdam
Posts: 10,211
Thanks: 333
Thanked 2,694 Times in 2,410 Posts
Another ( awkish Linux ) awk:

Code:
awk 'NF && ORS=++i%7?FS:RS' file

The Following User Says Thank You to Scrutinizer For This Useful Post:
panyam (03-01-2013)
Sponsored Links
    #5  
Old Unix and Linux 03-01-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 May 2015, 10:54 AM EDT
Location: Galactic Empire
Posts: 3,402
Thanks: 240
Thanked 1,216 Times in 1,142 Posts
Another approach:

Code:
grep -v '^$' file | paste - - - - - - -

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk in horizontal and vertical math busyboy Shell Programming and Scripting 6 02-15-2013 02:37 AM
Vertical And Horizontal Pivoting kmsekhar Shell Programming and Scripting 3 02-01-2012 06:32 AM
vertical to horizontal andrisetia UNIX for Dummies Questions & Answers 6 10-03-2011 06:03 AM
Horizontal to vertical Xterra UNIX for Dummies Questions & Answers 3 09-09-2011 11:54 AM
combine files in horizontal way, not vertical. jimmy_y Shell Programming and Scripting 3 10-29-2009 05:10 AM



All times are GMT -4. The time now is 01:39 AM.