Converting csv to tsv and back


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Converting csv to tsv and back
# 8  
Old 05-04-2008
Macintosh-2:$ sed --version
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]


When I do man sed, it has this in there:
Quote:
(The letter ell.) Write the pattern space to the standard output
in a visually unambiguous form. This form is as follows:

backslash \\
alert \a
form-feed \f
carriage-return \r
tab \t
vertical tab \v
I don't get why it doesn't work....
# 9  
Old 05-04-2008
Oh, okay - got it!

sed "s/,/"$'\t'/g test

works like a charm!
# 10  
Old 05-06-2008
Secondary question...

any advice on how I could specify which columns to print, upon converting a csv to a tsv? Like if I only wanted the first three columns of the tab-separated value to print?
# 11  
Old 05-07-2008
Code:
awk 'BEGIN{OFS="\t"}{print $1,$2,$3}'  file

Regards
# 12  
Old 05-07-2008
Thank you Franklin, works perfectly. Some csv files have quotes around the fields (e.g. "one","two","three","four") - how can I use awk to remove these upon printing as tsv?
# 13  
Old 05-07-2008
To remove the double quotes with the above script:

Code:
awk 'BEGIN{OFS="\t"}{gsub("\"","");print $1,$2,$3}'  file

Regards
# 14  
Old 05-07-2008
Thank you sir. I ended up with:
awk '{gsub(/,/, "\t")gsub("\"","");print}NR==3{exit 0}' test

using your scripts as a basis for getting this figured out. Thank you so much.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting XML to CSV

Hello, For i while i have been using XMLStarlet to convert several XML files to CSV files. So far this always went fine. Today however i got a new XML format however but i cannot find out how to get the data i need. Below is part of the code where it shows the different format. What... (10 Replies)
Discussion started by: SDohmen
10 Replies

2. Shell Programming and Scripting

Converting csv to html format

Below is the code I have - How can I convert the data in the csv into 3 tables in html. instead of 1 table. Attached is the format I am getting. (1 Reply)
Discussion started by: archana25
1 Replies

3. Shell Programming and Scripting

Converting CSV to ascii format

Hej All, I have a file like this which is a comma dilimited: input: 6000318,-263.011520678,-59.05869872409,587.67924868792 6000319,-265.6996842902,-50.24902479999,590.65693082607 6000320,-238.1333898366,-288.801232595,633.75332173496... (5 Replies)
Discussion started by: Johanni
5 Replies

4. Shell Programming and Scripting

awk with tsv & csv

Hi! HELP! I have a few issues... I have a tsv with headers time, binary time, bytes, and bits. I'm trying to extract only time & bits. (Trying to graph throughput) Using: awk -F"\t" '{print $1, "\t"$4}' infile.tsv > outfile.tsv Output is only the headers: time bits Thinking it... (2 Replies)
Discussion started by: calitiggr
2 Replies

5. Shell Programming and Scripting

Converting txt file in csv

HI All, I have a text file memory.txt which has following values. Average: 822387 7346605 89.93 288845 4176593 2044589 51883 2.47 7600 i want to convert this file in csv format and i am using following command to do it. sed s/_/\./g <... (3 Replies)
Discussion started by: mkashif
3 Replies

6. UNIX for Dummies Questions & Answers

Converting spaces to csv

I'm new to shell scripting and I have a file with positional columns. The rows look like this: 222 3333 44444 55 55 55 55 5555 59999 222 3333 44444 55 55 55 55 5555 59999 Not every row has the same number of spaces between the seven columns. They can range anywhere... (11 Replies)
Discussion started by: jkandel
11 Replies

7. UNIX for Dummies Questions & Answers

Converting HTML to CSV

Hi, I need to convert a relatively large html file (1.5megs) into CSV under Unix. How would I be able to do this? Much thanks. (3 Replies)
Discussion started by: Jexel
3 Replies

8. Shell Programming and Scripting

converting text to csv format

I am trying to check each line and based on first two digits, the comma needs to be place. I checked in the earlier post where the text is converted to csv with a tab delimited. Here is the test file that needs to be changed to csv 11 051701 22 051701 330123405170105170112345... (13 Replies)
Discussion started by: gthokala
13 Replies

9. Shell Programming and Scripting

Converting %## back to special characters from an HTML form

I have an HTML form that sends email to a large list of users one at a time by matching an email address in peoplesoft to their username. It works great, except that special characters are converted to %## format. Is there a library of these I can use to sed them back (yes this is a crappy UNIX... (1 Reply)
Discussion started by: 98_1LE
1 Replies

10. Shell Programming and Scripting

Converting csv to xls

Hi, Can anyone tell the option to change the file type in unix. i.e. if a file is in csv(Comma Separating Values) format, it should be changed to xls(ordinary MS-Excel) format. But renaming command is not changing to correct file format. Thanks in advance, Milton. (1 Reply)
Discussion started by: miltony
1 Replies
Login or Register to Ask a Question