首页 \ 问答 \ awk:通过特定的分隔符删除字符串(awk: remove strings by specific delimiter)

awk:通过特定的分隔符删除字符串(awk: remove strings by specific delimiter)

我在文件中有几列,其中第二列有“:”分隔符,我想删除第二列中的第一,第三和第四个字符串,并在该列中留下第二个字符串。 但我有正常的分隔符空间,所以我不知道。

input:

--- 22:16050075:A:G 16050075 A G
--- 22:16050115:G:A 16050115 G A
--- 22:16050213:C:T 16050213 C T
--- 22:16050319:C:T 16050319 C T
--- 22:16050527:C:A 16050527 C A

desired output:

--- 22 16050075 16050075 A G
--- 22 16050115 16050115 G A
--- 22 16050213 16050213 C T
--- 22 16050319 16050319 C T
--- 22 16050527 16050527 C A

Wrong:
cat df.txt | awk -F: '{print $1, $3, $6, $7, $8}'

--- 22 A
--- 22 G
--- 22 C
--- 22 C
--- 22 C

但我做不到。 awk和sed命令可以做到吗?

谢谢。


I have few columns in a file, in which the second column has ":" delimiter and I would like to remove the first, third and fourth strings in the second column and left the second string in that column. But I have the normal delimiter space, so I have no idea.

input:

--- 22:16050075:A:G 16050075 A G
--- 22:16050115:G:A 16050115 G A
--- 22:16050213:C:T 16050213 C T
--- 22:16050319:C:T 16050319 C T
--- 22:16050527:C:A 16050527 C A

desired output:

--- 22 16050075 16050075 A G
--- 22 16050115 16050115 G A
--- 22 16050213 16050213 C T
--- 22 16050319 16050319 C T
--- 22 16050527 16050527 C A

Wrong:
cat df.txt | awk -F: '{print $1, $3, $6, $7, $8}'

--- 22 A
--- 22 G
--- 22 C
--- 22 C
--- 22 C

but I can not do it right. can awk and sed command can do it?

Thank you.


原文:https://stackoverflow.com/questions/42384007
更新时间:2022-08-31 17:08

最满意答案

只需调用SVG DOM getPointAtLength方法即可

SVGPoint getPointAtLength(in float distance)

例如var point = document.getElementById("pathId").getPointAtLength(150);


OK, here is a possible solution to how to find the distance from the beginning of the path to any one of the points which were used to define it. The idea is to to create a temporary sub path of the original path for each of the points which make it up, and then use 'getToalLength()' to calculate the distance of this sub-path. This distance reflects the distance in the entire original path starting from the first point up to the current point. Now, after the distance has been calculated, it can be stored, and the temporary path can be removed. This way we can calculate and store the distance from the beginning of the original path to each of the points which make it up. Here is the code I use (a bit simplified to focus just on this goal):


            var pointsAry = [["M",10,10],["T",30,50],["T",60,100],["T",80,200],["T",300,400]], subPath, path = [];
            for (var i = 0 ; i < pointsArray.length ; i++) {
                path.push(pointsAry[i]);
                subPath = paper.path(path).attr({ "stroke-opacity": 0 }); // make the path invisible
                pointsAry[i].subPathSum = subPath.getTotalLength();
                subPath.remove();
            }

paper is created via Raphaeljs which also supplies the getTotalLength() function. Note the lines are created invisibly because their opacity is 0, and anyhow they are immediately removed.

相关问答

更多