1. 需求
在提供数据或者测试的时候, 为了保证数据的随机性, 需要从现有文件中抽取子集
2. 方法
shuf
取自"shuffle", 意指洗牌
shuf
- generate random permutationsDESCRIPTION
- Write a random permutation of the input lines to standard output.
- Mandatory arguments to long options are mandatory for short options too.
基本使用
# 1. 抛硬币
[root@maxc107 leon]# shuf -r -n 10 -e '正' -e '反'
反
反
正
正
反
反
正
正
反
正
# 2. 区间取值
[root@maxc107 leon]# shuf -i 1-20 -n 5
5
19
1
3
11
# 3. 文件随机读
shuf -n 10000 domain.csv -o /tmp/1w.domain
网友评论