Converting Tab delimited file to Comma delimited file in Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting Tab delimited file to Comma delimited file in Unix
# 15  
Old 01-19-2006
Quote:
Originally Posted by charan81

I believe we need to convert all the
2 tab spaces into 1 tab in all the records then convert that single tab space into comma (,).

Kindly help me in this..
The below sed command does that. Did you try this?

Code:
sed -e 's/               /       /' -e 's/       /,/g' tab_del

# 16  
Old 01-19-2006
Code:
you can try this if the tabs are going to 1 or more than 1 between fields...


sed 's/        [         ]*/,/g' tab_del

after s/.... there is <tab> ( not spaces ) and within [] there is one more tab ( not spaces )....

this will replace any number of tabs to single comma...


Last edited by mahendramahendr; 01-19-2006 at 10:39 AM..
# 17  
Old 01-20-2006
Guys...

Could u people let me know on how to find whether
Spaces between the fields in a record is a "Tab" or "Multiple Spaces".
# 18  
Old 01-20-2006
Code:
/export/home/test/mons>cat -vet hh
adasd^Isdfsdf^I^Isdfsdfdsf$
dsfdsf sdf sdfsd sfsdfsdf$

cat -vet will display all the control characters

^I represents tab

and space is shown as " " only.
# 19  
Old 01-20-2006
when i issue cat dmlog.txt i get

ANALYZE DLS_DM COMPLETE GE 24-OCT-05
LOAD_STAGE STAGE_LOAD COMPLETE C0 16-DEC-05



when i issue cat -vet dmlog.txt i get

ANALYZE DLS_DM COMPLETE GE 24-OCT-05 $
LOAD_STAGE STAGE_LOAD COMPLETE C0 16-DEC-05 $


Is that mean only spaces are there b/w fields ?? I dont see any ^I characters..
# 20  
Old 01-20-2006
Here is what i get...

when i issue cat dmlog.txt i get

ANALYZE DLS_DM COMPLETE GE 24-OCT-05
LOAD_STAGE STAGE_LOAD COMPLETE C0 16-DEC-05


when i issue cat -vet dmlog.txt i get

ANALYZE DLS_DM COMPLETE GE 24-OCT-05 $
LOAD_STAGE STAGE_LOAD COMPLETE C0 16-DEC-05 $



Is that mean only spaces are there b/w fields ?? I dont see any ^I characters..

If so,

How to convert those spaces into comma ??
# 21  
Old 01-20-2006
then this command will do

Code:
sed 's/ /,/g' filename

or

tr " " "," < filename

I can see some extra spaces at the last of each line. If you don't want a comma at the last then you can strip the extra space and convert. The below will do that

Code:
sed -e 's/^\(.*\) $/\1/' -e 's/ /,/g' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

4. UNIX for Dummies Questions & Answers

Need help with tab delimited file in unix

Hi, I need urgent help with a tab delimited file I am working on. This is the file : TTTT|YYYYYYY|jargon-journal|MP0000000UID||"j1, j2, j3" I need th following output: TTTT|YYYYYYY|jargon-journal|MP0000000UID||ji TTTT|YYYYYYY|jargon-journal|MP0000000UID||j2... (8 Replies)
Discussion started by: rayarnab
8 Replies

5. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

6. Shell Programming and Scripting

how to convert comma delimited file to tab separator

Hi all, How can i convert comma delimited .csv file to tab separate using sed command or script. Thanks, Krupa (4 Replies)
Discussion started by: krupasindhu18
4 Replies

7. Shell Programming and Scripting

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

8. Shell Programming and Scripting

Converting comma separated to pipe delimited file

Hi, I came across a very good script to convert a comma seperated to pipe delimited file in this forum. the script serves most of the requirement but looks like it does not handle embedded double quotes and commas i.e if the input is like 1234, "value","first,second", "LDC5"monitor",... (15 Replies)
Discussion started by: anijan
15 Replies

9. Shell Programming and Scripting

Retrieving values from tab-delimited file in unix script

Hi I am trying to retrieve values from a tab-delimited file.I am using while read record value=`echo $record | cut -f12` done Where 12 is the column no i want retieve and record is one line of the file. But it is returning the full record. Plz help (4 Replies)
Discussion started by: akashtcs
4 Replies

10. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 Replies
Login or Register to Ask a Question