Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I randomly merge two input files to one output file using unix tools?

Tags:

linux

unix

I have two text files, of different sizes, which I would like to merge into one file, but with the content mixed randomly; this is to create some realistic data for some unit tests. One text file contains the true cases, while the other the false.

I would like to use standard Unix tools to create the merged output. How can I do this?

like image 791
nwaltham Avatar asked Dec 19 '25 02:12

nwaltham


1 Answers

Random sort using -R:

$ sort -R file1 file2 -o file3
like image 138
Chris Seymour Avatar answered Dec 21 '25 17:12

Chris Seymour