我想在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" $0 }' file