且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

BASH-随机播放文件中字符串中的字符

更新时间:2022-11-13 23:08:11

使用perlruby

$ # 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