Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert tab delimited file to comma delimited

Status
Not open for further replies.

hcclnoodles

IS-IT--Management
Jun 3, 2004
123
GB
Hi there

Just wondered if someone could help me out

I have a file that has been delimited by tabs, ie

field1<tab>fiield2<tab>field3

Does anybody know a command that will convert tabs to commas throughout the entire file?

Note: there are a number of unpopulated fields in the file so after the conversion I would expect to see ,,,,,, in place of the <tab><tab><tab><tab><tab> as it is currently

any help on this would be greatly appreciated
 
Something like this ?
tr '\t' ',' </path/to/input >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for that PHV it works perfect !! I have one more question if i may (which i forgot to ask above) the file has 30 fields (and as such 30 commas) however, I dont need the last 15 fields for my program, so basically i want some way of removing these. I would like it to remove everything to the right the 15th comma (including that comma itself) I s this possible ?

thanks
Gary
 
man awk

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Another way:
man cut

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Try this (untested) awk script

BEGIN {FS="\t";OFS=","}
{
for (j=1;j<=15;j++) printf $j
print ""
}

CaKiwi
 
thanks guys ive used the following and it works perfectly

tr '\t' ',' <input_file>output_file

cut -d, -f-12 input_file>output_file


thanks again
 
me again....thanks for all your help, now i know this is a bit of a dumb question (im a still quite new to this)

I now have the 3 commands i am going to use in my script, they will be

tr '\t' ',' <input_file>output_file
cut -d, -f-12 input_file>output_file
tail +2 input > output

My question is , Do i have to keep producing an output file after each command or is there a way using pipes that i can get all of these commands to be run on my file but with just the one command??

 
Like this ?
tr '\t' ',' <input_file | cut -d, -f-12 | tail +2 >output


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
something like this?

Code:
tr '\t' ',' <input_file | cut -d, -f-12 |tail +2 > output

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top