我有一个文件(filename.txt
)具有以下结构:
>line1
ABC
>line2
DEF
>line3
GHI
>line4
JKL
我想打乱字符串中的字符not开始机智>
。输出将(例如)如下所示:
>line1
BCA
>line2
DFE
>line3
IHG
>line4
KLJ
这就是我尝试打乱字符串中的字符的方法:sed 's/./&\n/' | shuf | tr -d "\n"
。看起来它可以工作,但它没有考虑换行符。此外,它对所有数据执行命令,而不仅仅是在不以>
.
With perl
and ruby
$ # split// to get individual characters
$ # join "" to join characters with empty string
$ # if !/^>/ to apply the change only for lines not starting with >
$ # alternate: perl -MList::Util=shuffle -lne 'print /^>/ ? $_ : shuffle split//'
$ perl -MList::Util=shuffle -lpe '$_=join "", shuffle split// if !/^>/' ip.txt
>line1
CBA
>line2
FED
>line3
IHG
>line4
JKL
$ # $_.chars to get individual characters
$ # * "" to join array elements with empty string
$ ruby -lpe '$_ = $_.chars.shuffle * "" if !/^>/' ip.txt
>line1
BAC
>line2
EDF
>line3
GHI
>line4
JKL
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)