Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

command for converting 4 column data to 1 column

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-11-2011
rpf rpf is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 15 July 2013, 12:05 PM EDT
Posts: 52
Thanks: 47
Thanked 0 Times in 0 Posts
command for converting 4 column data to 1 column

dear friends I want to convert four column data to one column data. For example:

from

Code:
1, 2, 3, 4
5, 6, 7, 8

to

Code:
1
2
3
4
5
6
7
8

what is the general command for that type of convertion.

thanks

Last edited by zxmaus; 12-11-2011 at 10:50 PM.. Reason: added tags
Sponsored Links
    #2  
Old Unix and Linux 12-11-2011
bartus11's Unix or Linux Image
bartus11 bartus11 is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 3 August 2016, 11:03 AM EDT
Posts: 3,733
Thanks: 7
Thanked 1,153 Times in 1,123 Posts

Code:
sed 's/, /\n/g' file

The Following User Says Thank You to bartus11 For This Useful Post:
rpf (12-12-2011)
Sponsored Links
    #3  
Old Unix and Linux 12-11-2011
tarun_agrawal tarun_agrawal is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 29 May 2012, 10:09 PM EDT
Posts: 87
Thanks: 0
Thanked 16 Times in 15 Posts

Code:
tr ',' '\n' < filename


Last edited by zxmaus; 12-11-2011 at 10:49 PM.. Reason: added code tags
The Following User Says Thank You to tarun_agrawal For This Useful Post:
rpf (12-12-2011)
    #4  
Old Unix and Linux 12-12-2011
palanisvr palanisvr is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 23 March 2015, 3:30 AM EDT
Location: /home/india
Posts: 105
Thanks: 1
Thanked 14 Times in 14 Posts
Try this


Code:
cat file.txt |tr  ',' '\n' | tr -d ' '

The Following User Says Thank You to palanisvr For This Useful Post:
rpf (12-12-2011)
Sponsored Links
    #5  
Old Unix and Linux 12-12-2011
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
Or even (getting rid of the space characters first):

Code:
sed -e "s/ //g" filename | tr ',' '\n'

Sponsored Links
    #6  
Old Unix and Linux 12-12-2011
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 10 September 2017, 7:04 AM EDT
Location: India
Posts: 1,975
Thanks: 31
Thanked 574 Times in 547 Posts
The Perl way Linux


Code:
perl -pe 's/, /\n/g' filename

Sponsored Links
Closed

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
Copy the data column to adjacent column bharathappriyan Shell Programming and Scripting 7 07-23-2010 01:49 AM
Moving data from a specified column/row to another column/row jl487 Shell Programming and Scripting 2 06-05-2010 12:07 AM
row to column and position data in to fixed column width baluchen Shell Programming and Scripting 4 03-15-2010 06:46 AM
Split Data in one column into 2 column in Excel using DOS or VBScript dashing201 Windows & DOS: Issues & Discussions 3 03-12-2010 05:04 AM
Changing one column of delimited file column to fixed width column manneni prakash Shell Programming and Scripting 5 06-22-2009 05:27 AM



All times are GMT -4. The time now is 02:22 PM.