MyTetra Share
Делитесь знаниями!
randomly shuffling files in bash
Время создания: 14.01.2015 15:45
Раздел: root - Linux - Console - bash
Запись: Yurons/mytetra/master/base/142123952324hhlyda57/text.html на raw.github.com

get_some_lines | sort -R

or

get_some_lines | shuf

if you don't have shuf or your sort doesn't know the -R, you can use for example:

standard perl:

get_some_lines | perl -MList::Util=shuffle -e 'print shuffle<STDIN>'

or BASH script

get_some_lines | while IFS= read -r line

do

printf "%06d %s\n" $RANDOM "$line"

done | sort -n | cut -c8-

the same numbered sort trick with awk

get_some_lines | awk 'BEGIN{srand()}{printf "%06d %s\n", rand()*1000000, $0;}' | sort -n | cut -c8-

In your case, the get_some_lines should be the:

cat file1 file2 #or cat file2 file1 :)


 
MyTetra Share v.0.65
Яндекс индекс цитирования