Making a Tab delimiter file to Comma


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Making a Tab delimiter file to Comma
# 8  
Old 01-31-2012
awk -F, -v OFS="\t" '{ $1=$1 } 1' test1.txt > test2.txt
# 9  
Old 01-31-2012
Like I said, try nawk.
# 10  
Old 02-01-2012
nawk worked..But the file which was tab delimited is just the same..It did not change to comma delimiter..Please advice
# 11  
Old 02-01-2012
The , and tab were reversed. try:
Code:
nawk -F\\t '{$1=$1}1' OFS=, filename > outfile

or
Code:
tr \\t , <filename > outfile

# 12  
Old 02-01-2012
worked perfect..Awesome

Thanks

---------- Post updated at 09:48 AM ---------- Previous update was at 07:01 AM ----------

The problem am now facing is, there is an account say Energy OX Place...Now what this is doing is, its inserting an comma in between that account name as well...How do i get rid of this...Because my file has some 20 columns separated by a Tab and there are accounts with names of that kind...any workaround for this??????
# 13  
Old 02-01-2012
Tabs inside your columns is a pretty big problem. It can tell there's too many columns, but not which ones should go where. You should re-export the data using a delimiter that's not in your data.

If it's a few, specific lines, you might be able to skip those lines and put them in a separate file to process by hand to append to the file when you're done. This may change the order of the lines though.

Code:
$ awk -F\\t -v OFS="," '
        (NF>20) { print $0 > "badlines"; L++; next }
        { $1=$1; print }
        END { print L " bad lines" >"/dev/stderr" }' input > output
$ vim badlines
$ cat badlines >> output

Substitute the exact value of the number of columns for 20... any time it finds a line with too many columns, it will print it raw (unchanged) into badlines for you to hand-edit and exclude them from 'output'.

Last edited by Corona688; 02-01-2012 at 12:02 PM.. Reason: important typo, NR vs NF
# 14  
Old 02-01-2012
Are you sure your columns are tab delimited and not fixed width? Could you post a sample, preferably with a line with tabs inside the columns?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace comma delimiter by newline

The input file is as below AR,age,marks,roll,section,evin,25,80,456,A,atch,23,56,789,B,eena,24 ,78H245,C,Ps,ot,ecessary,hat,ame comes first then age and rest AR AZ,kevin,25,80,456,A,Satch,23,56,789,Satch,23,56,789,B,Meena,24,78,H245,C,AZ ................ ................ I am writting... (8 Replies)
Discussion started by: millan
8 Replies

2. 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

3. Shell Programming and Scripting

Exporting data into Comma Delimiter.

Hi, Requirement: Exporting data from Oracle to UNIX into "Comma" delimiter. Help Needed: I was able to connect to Oracle and import the data. But please let me know while importing the data I need to make it into Comma delimiter flat file. For Example: Source Data - 100 ABC TLead... (6 Replies)
Discussion started by: arunvasu2
6 Replies

4. Shell Programming and Scripting

comma delimiter and space

I have a csv file and there is a problem which I need to resolve. Column1,Column2,Colum3,Column4 ,x,y,z ,d,c,v t,l,m,n ,h,s,k ,k,,y z,j, ,p Now if you see column1 for row 1 and row 4 though they are null there is a space but in case of row2 and row 5 there is no space. I want row... (3 Replies)
Discussion started by: RubinPat
3 Replies

5. UNIX for Dummies Questions & Answers

Delimiter: Tab or Space?

Hello, Is there a direct command to check if the delimiter in your file is a tab or a space? And how can they be converted from one to another. Thanks, G (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

6. UNIX for Dummies Questions & Answers

Replacing Comma by Tab

Hi All, i have a file test.txt as shown below, 1,test,test111 2,rest,rest222 i want to replace the commas by tab delimiter.., it should be like, 1 test test111 2 rest rest222 i tried the following code, sed 's/,/\\t/g' test.txt >> ouptut.txt (9 Replies)
Discussion started by: Serious Sam
9 Replies

7. Shell Programming and Scripting

replace comma(,) with Tab

hi all, i have a file with commas(,). i want to replace all the commas with tab(\t). Plz help...its urgent... (3 Replies)
Discussion started by: vikas_kesarwani
3 Replies

8. Shell Programming and Scripting

append data in a file by using tab delimiter

Hi, I need to append the data in to a file by using tab delimiter. eg: echo "Data1" >> filename.txt echo "\t" >> filename.txt (its not working) echo "Data2" >> filename.txt. the result sould be like this. Data1 Data2 (6 Replies)
Discussion started by: Sharmila_P
6 Replies

9. Shell Programming and Scripting

Cutting a tab delimiter file

I have a 30 column tab delimited record file. I need to extract the first 10column. The following command to cut was not working cut -f 1-10 -d "\t" filename. Could any one keep on this . Thanks in Advance (4 Replies)
Discussion started by: vinod.thayil
4 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