tsv

How do I convert a tab-separated values (TSV) file to a comma-separated values (CSV) file in BASH?

二次信任 提交于 2020-01-22 12:54:10
问题 I have some TSV files that I need to convert to CSV files. Is there any solution in BASH, e.g. using awk , to convert these? I could use sed , like this, but am worried it will make some mistakes: sed 's/\t/,/g' file.tsv > file.csv Quotes needn't be added. How can I convert a TSV to a CSV? 回答1: Update : The following solutions are not generally robust , although they do work in the OP's specific use case; see the bottom section for a robust, awk -based solution . To summarize the options

How do I convert a tab-separated values (TSV) file to a comma-separated values (CSV) file in BASH?

拜拜、爱过 提交于 2020-01-22 12:53:27
问题 I have some TSV files that I need to convert to CSV files. Is there any solution in BASH, e.g. using awk , to convert these? I could use sed , like this, but am worried it will make some mistakes: sed 's/\t/,/g' file.tsv > file.csv Quotes needn't be added. How can I convert a TSV to a CSV? 回答1: Update : The following solutions are not generally robust , although they do work in the OP's specific use case; see the bottom section for a robust, awk -based solution . To summarize the options

Complex XML to TSV using XSLT

风格不统一 提交于 2020-01-04 15:54:31
问题 I have found a couple of previous questions that address parts of my problem (see here and here, but I'm having trouble integrating them. I have a set of XML records that I want to transform to tab-delimited format. However, not all the XML records have all fields, and some contain multiple instances of a field. Two sample XML records: <?xml version="1.0" encoding="UTF-8" ?> <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

Complex XML to TSV using XSLT

痴心易碎 提交于 2020-01-04 15:52:54
问题 I have found a couple of previous questions that address parts of my problem (see here and here, but I'm having trouble integrating them. I have a set of XML records that I want to transform to tab-delimited format. However, not all the XML records have all fields, and some contain multiple instances of a field. Two sample XML records: <?xml version="1.0" encoding="UTF-8" ?> <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

Fast read different type of data with same command, better seperator guessing [duplicate]

怎甘沉沦 提交于 2020-01-04 14:18:20
问题 This question already has answers here : Reading aligned column data with fread (2 answers) Closed last year . I have LD data, sometimes raw output file from PLINK as below (notice spaces - used to make the output pretty, notice leading and trailing spaces, too): write.table(read.table(text=" CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2 1 154834183 rs1218582 1 154794318 rs9970364 0.0929391 1 154834183 rs1218582 1 154795033 rs56744813 0.10075 1 154834183 rs1218582 1 154797272 rs16836414 0.106455 1

Combining certain columns of several tab-delimited files based on first column

假装没事ソ 提交于 2020-01-01 16:57:09
问题 1st column in inFile contains a string not necessarily present in all inFiles 2nd and 7th columns in each inFile contains the Title# strings Using AWK, I cannot piece this together correctly. My use of descriptive variables will hopefully help clarify what I'm trying to do. These are components I think I need: tab-separated input files: -F'\t' increment the strings in the 1st column, but only add each 'name' once to the '1stColumnNames': !1stColumnNames[$1]++ { name[++i] = $1 } make a new

PHP to write Tab Characters inside a file?

偶尔善良 提交于 2019-12-30 00:13:31
问题 How do i simply write out a file including real tabs inside? tab means real tab which is not the spaces . How to write the tab or what is the character for real tab ? For example here: $chunk = "a,b,c"; file_put_contents("chunk.csv",$chunk); What character should i use to get tabs instead of Commas (,) there? In the output file, there should be real tabs between the seperated words. Real Tabs means, a true wide space we get when we press the <tab> key in a text-editor. 回答1: The tab character

TSV: how to concatenate field 2s if field 1 is duplicate

折月煮酒 提交于 2019-12-24 14:52:48
问题 I'm building a Swedish-English sentence deck for ANKI from the Creative Common licensed content of tatoeba.org. Please help me turning sample 1 to sample 2 (preferably in bash): #sample1 a 1 a 2 b 3 c 4 c 5 #sample2 a 1<br>2 b 3 c 4<br>5 Duplicates in field 1 are always subsequent. Thank you! 回答1: One way using awk : awk 'p==$1{printf "<br>%s", $2;next}{if(p){print ""};p=$1;printf "%s", $0}END{print ""}' file a 1<br>2 b 3 c 4<br>5 回答2: perl -ape '$_ = ($l eq $F[0]) ? "<br>$F[1]" : "\n@F"; $l=

sqlite3 import with quotes

心不动则不痛 提交于 2019-12-22 04:12:29
问题 I am trying to import a collection of data that has quotes within the fields. They are currently tab separated. From what I can understand according to the docs (http://www.sqlite.org/cvstrac/wiki?p=ImportingFiles), the sqlite shell should interpret quotes literally and I assume that means I shouldn't have a problem. I've been running into a problem on this line: 1193782372 Lips Like Sugar (12" Mix) Echo & the Bunnymen 80's/12": The Extended Collection a76d9b04-51d9-4672-801f-356ab36dbae7

Convert an array of json objects to tsv (python)

一个人想着一个人 提交于 2019-12-21 06:06:45
问题 Suppose that I have the following array of json objects, I want to convert them to the tsv format. [ { "x": "1", "y": "2", "z": "3" }, { "x": "6", "y": "7", "z": "B" } ] Does anyone have a good solution to this? (python's json module only allow reading json object, but how to read an array of json object?) x<TAB>y<TAB>z 1<TAB>2<TAB>3 6<TAB>7<TAB>8 回答1: The first step is to convert from a JSON string to an array of Python objects using, for example, json.loads . The final step is to write the