添加一个随机变量到 Sed \a 每一个新行
Add a random variable into Sed \a every new lines
我想在 sed
创建的每一行新行中添加一个随机数
目前我的命令是:
sed "a path/to/file$(($RANDOM%7))" tmp/line.txt
结果:
line1
path/to/file1
line3
path/to/file1
line5
path/to/file1
line7
path/to/file1
...(22K lines)
预期:
line1
path/to/file1
line3
path/to/file0
line5
path/to/file7
line7
path/to/file5
...(22k lines)
使用 shuf 和 GNU sed:
shuf -r -e 'path/to/file'{0..7} | sed 'R /dev/stdin' file
或者 shuf 和 awk:
shuf -r -i 0-7 | awk '1; { getline < "/dev/stdin"; print "path/to/file" [=11=] }' file
或者只是 awk:
awk 'BEGIN { srand() } 1; { print "path/to/file" int(rand() * 8) }' file
我想在 sed
创建的每一行新行中添加一个随机数目前我的命令是:
sed "a path/to/file$(($RANDOM%7))" tmp/line.txt
结果:
line1
path/to/file1
line3
path/to/file1
line5
path/to/file1
line7
path/to/file1
...(22K lines)
预期:
line1
path/to/file1
line3
path/to/file0
line5
path/to/file7
line7
path/to/file5
...(22k lines)
使用 shuf 和 GNU sed:
shuf -r -e 'path/to/file'{0..7} | sed 'R /dev/stdin' file
或者 shuf 和 awk:
shuf -r -i 0-7 | awk '1; { getline < "/dev/stdin"; print "path/to/file" [=11=] }' file
或者只是 awk:
awk 'BEGIN { srand() } 1; { print "path/to/file" int(rand() * 8) }' file