The UNIX and Linux Forums  

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
Combining information from a comma delimited file vzismann UNIX for Dummies Questions & Answers 1 08-06-2007 07:20 PM
Parsing comma delimited text file chengwei Shell Programming and Scripting 5 02-23-2007 05:38 AM
Loading a comma Delimited file into an Array grandtheftander UNIX for Dummies Questions & Answers 2 07-26-2006 02:19 PM
Comma Delimited file dbrundrett Shell Programming and Scripting 2 04-05-2004 11:50 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 01-17-2006
charan81 charan81 is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 19
Question Converting Tab delimited file to Comma delimited file in Unix

Hi,

Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix

Thanks!!
  #2 (permalink)  
Old 01-17-2006
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Quote:
Originally Posted by charan81
Hi,

Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix

Thanks!!
You can use sed to convert the Tab delimited file to a comma delimited file


Code:
/export/home/test/mona>cat tab_del.dat
1       2       3       4       5
6       7       8       9       10
/export/home/test/mona>sed 's/        /,/g' tab_del.dat
1,2,3,4,5
6,7,8,9,10

Redirect the output of this to another file and rename it.
  #3 (permalink)  
Old 01-18-2006
charan81 charan81 is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 19
When i use

/export/home/test/mona>sed 's/ /,/g' tab_del.dat

I m getting like this..
1,, 2 3 4 5,
6,, 7 8 9 10,


Where i need like this
1,2,3,4,5
6,7,8,9,10

Plz help me out on this..

Thanks!!
  #4 (permalink)  
Old 01-18-2006
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Hi,

In the below code, the integers are seperated by tab and not multiple spaces.

The same way in the sed command you should give a tab and not multiple spaces. I think problem occurs when you copy the below contents and run. Don't copy the contents, form the data file of your own and run the sed command.

Let me know if you still face any problem


Code:
/export/home/test/mona>cat tab_del.dat
1press the tab key here2       3       4       5
6       7       8       9       10
/export/home/test/mona>sed 's/        /,/g' tab_del.dat
1,2,3,4,5
6,7,8,9,10

  #5 (permalink)  
Old 01-18-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Use tr


Code:
tr '\t' ',' < tab-delimited-file > comma-delimited-file

  #6 (permalink)  
Old 01-18-2006
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
i think it is simpler to convert using tr. You can use sed but sed will not recognize escape sequences like \n,\t.. but all these will be accpeted in tr.

Great going Vino
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 02:40 AM.


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