Home Man
Search
Today's Posts
Register

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.

how to convert comma delimited file to tab separator

Tags
convert comma file to tab separator, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 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 02: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 to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux convert Comma delimited file to pipe shieksir Shell Programming and Scripting 4 11-06-2017 05:22 PM
Need to convert a pipe delimited text file to tab delimited raja kakitapall UNIX for Dummies Questions & Answers 9 04-06-2015 06:25 AM
How to convert a comma delimited string to records or lines of text? newbie_01 UNIX for Dummies Questions & Answers 2 11-05-2014 04:32 AM
Add a field separator (comma) inside a line of a CSV file Tawpie UNIX for Dummies Questions & Answers 9 06-15-2014 08:09 PM
Need a script to convert comma delimited files to semi colon delimited CarpKing Shell Programming and Scripting 4 02-14-2013 06:33 AM
How to convert a space delimited file into a pipe delimited file using shellscript? nithins007 Shell Programming and Scripting 7 09-25-2011 05:33 AM
Urgent! need help! how to convert this file into comma delimited format natalie23 UNIX for Advanced & Expert Users 2 08-28-2009 04:39 AM
how to convert this file into comma delimited format natalie23 Shell Programming and Scripting 1 08-28-2009 04:25 AM
convert a pipe delimited file to a':" delimited file priyanka3006 Shell Programming and Scripting 6 05-26-2009 10:53 AM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 08:24 AM


All times are GMT -4. The time now is 06:36 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password