我正在尝试对文本文件中的字符串使用tr
命令,以便我可以用新行字符替换它。例如,我的文件
biological_process GO:0000001 mitochondrion inheritance is_a GO:0048308 organelle inheritance
现在我想将其转换为喜欢这个
biological_process GO:0000001 mitochondrion inheritance
GO:0048308 organelle inheritance
我之前使用过tr
命令,我认为它会起作用,但是当我尝试像这样运行时它就会发生
test="biological_process GO:0000001 mitochondrion inheritance is_a GO:0048308 organelle inheritance"
echo $test | tr 'is_a' '\n'
b
olog
c
l
proce
GO:0000001 m
tochondr
on
nher
t
nce
GO:0048308 org
nelle
nher
t
nce
答案 0 :(得分:-1)
tr
翻译字符,而不是字符串。
$ sed 's/is_a/\n/g' <<< "biological_process GO:0000001 mitochondrion inheritance is_a GO:0048308 organelle inheritance"
biological_process GO:0000001 mitochondrion inheritance
GO:0048308 organelle inheritance
$ sed 's/is_a\s\+/\n/g' <<< "biological_process GO:0000001 mitochondrion inheritance is_a GO:0048308 organelle inheritance"
biological_process GO:0000001 mitochondrion inheritance
GO:0048308 organelle inheritance