Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个如下文件
-1 1 -1 2 -1 2 -1 2 0
我想通过挤压元素“-1”
tr -s '-1' file
但它不起作用。
添加
我使用 vcftools 将 vcf.gz 更改为元素为“0”、“1”或“2”的矩阵(例如,chr1.012)(缺失值为“-1”)。但我发现每一行的长度是不同的。所以我怀疑是不是因为“-1”。所以我想挤压“-1”元素。
您可以在sed
sed
$ echo "-1-1-1 2 -1" | sed -r 's/(-1)+/-1/g' -1 2 -1
-1用一个实例替换 s 的连续流。
-1
它不适用于tr,因为:
tr
-1将被视为具有两个字符的字符集,-而1不是单个标记-1
-
1
此外,即使您只有一个字符,也需要出现相邻的位置才能tr应用挤压操作