how to convert comma delimited file to tab separator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to convert comma delimited file to tab separator
# 1  
Old 02-21-2012
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
# 2  
Old 02-21-2012
Hi,
Try this,
Code:
sed 's/\,/\t/g' file >outfile
awk '{gsub(/\,/,"press tab");print;}' file >outfile

if you dont want use the new file to store the result and update in same file. just use the below cmd
Code:
awk '{gsub(/\,/,"press tab");a[NR]=$0;}END{for (i=1;i<=NR;i++){print a[i] >FILENAME;}}' file

press tab button in gsub replace str.
Cheers,
Ranga:-)

Last edited by rangarasan; 02-21-2012 at 03:08 PM.. Reason: added additional solution
# 3  
Old 02-21-2012
Code:
cat oldfile.txt | tr '[,]' '[\t]' > newfile.txt

# 4  
Old 02-21-2012
Quote:
Originally Posted by methyl
Code:
cat oldfile.txt | tr '[,]' '[\t]' > newfile.txt

Why the square brackets? If those are intended to be single character bracket expressions, tr does not support that syntax. Well, I should say, POSIX tr. Perhaps that is an older dialect? In modern implementations, that simply replaces [ with itself and ] with itself, a couple of no-ops, in addition to comma with tab.

Or am I overlooking something?

Regards,
Alister
# 5  
Old 02-22-2012
Quote:
Or am I overlooking something?
Obviously harmless if the square brackets are both sides. I had never noticed that unescaped [] were not treated as special characters in some syntaxes of Posix "tr".
Strangely I don't usually put [] for single characters but it ended up like that after simplifying the command.

The "tr" command line modifies the default translation table for that locale. There is no additional processing when the translate itself takes place.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux convert Comma delimited file to pipe

I have file in linux with comma delimited and string fields in double quotations ", I need to convert them to pipe delimiter please share your inputs. Example: Input: "2017-09-30","ACBD,TVF","01234",NULL,18,NULL,"686091802","BANK OF ABCD, LIMITED, THE",790456 Output: ... (4 Replies)
Discussion started by: shieksir
4 Replies

2. Shell Programming and Scripting

Convert pipe demilited file to vertical tab delimited

Hi All, How can we convert pipe delimited ( or comma ) file to vertical tab (VT) delimited. Regards PK (4 Replies)
Discussion started by: prasson_ibm
4 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. Shell Programming and Scripting

How to convert space&tab delimited file to CSV?

Hello, I have a text file with space and tab (mixed) delimited file and need to convert into CSV. # cat test.txt /dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST /dev/rmt/tsmmt37 ... (6 Replies)
Discussion started by: prvnrk
6 Replies

5. Shell Programming and Scripting

Convert a 3 column tab delimited file to a matrix

Hi all, I have a 3 columns input file like this: CPLX9PC-4943 CPLX9PC-4943 1 CPLX9PC-4943 CpxID123 0 CPLX9PC-4943 CpxID126 0 CPLX9PC-4943 CPLX9PC-5763 0.5 CPLX9PC-4943 CpxID13 0 CPLX9PC-4943 CPLX9PC-6163 0 CPLX9PC-4943 CPLX9PC-6164 0.04... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

6. Shell Programming and Scripting

Need a script to convert comma delimited files to semi colon delimited

Hi All, I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv... (4 Replies)
Discussion started by: CarpKing
4 Replies

7. UNIX for Dummies Questions & Answers

How to convert a text file into tab delimited format?

I have a text file that made using text editor in Ubuntu. However the text file is not being recognized as space or tab delimited, the formatting seems to be messed up. How can I convert the text file into tab delimited format? (3 Replies)
Discussion started by: evelibertine
3 Replies

8. UNIX for Advanced & Expert Users

Urgent! need help! how to convert this file into comma delimited format

Hi experts, I need urget help! I have the a text file with this format: Types of fruits Name of fruits 1,1 Farm_no,1 apple,1 pineapple,1 grapes,1 orange,1 banana,1 2,2--->this is the record seperator Farm_no,2 apple,1 pineapple,1 grapes,3 orange,2 banana,1 3,3--->this is the... (2 Replies)
Discussion started by: natalie23
2 Replies

9. Shell Programming and Scripting

how to convert this file into comma delimited format

Hi experts, I need urget help! I have the a text file with this format: Types of fruits Name of fruits 1,1 Farm_no,1 apple,1 pineapple,1 grapes,1 orange,1 banana,1 2,2--->this is the record seperator Farm_no,2 apple,1 pineapple,1 grapes,3 orange,2 banana,1 3,3--->this is the... (1 Reply)
Discussion started by: natalie23
1 Replies

10. Shell Programming and Scripting

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!! (22 Replies)
Discussion started by: charan81
22 Replies
Login or Register to Ask a Question