我想使用"sed"在文件的每一行中用随机数替换所有出现的数字.例如,如果我的文件在每行中的编号为892,我想用800到900之间的唯一随机数替换它.
输入文件:-
temp11;djaxfile11;892
temp12;djaxfile11;892
temp13;djaxfile11;892
temp14;djaxfile11;892
temp15;djaxfile11;892
Run Code Online (Sandbox Code Playgroud)
预期的输出文件: -
temp11;djaxfile11;805
temp12;djaxfile11;846
temp13;djaxfile11;833
temp14;djaxfile11;881
temp15;djaxfile11;810
Run Code Online (Sandbox Code Playgroud)
我正在尝试下面的内容: -
sed -i -- "s/;892/;`echo $RANDOM % 100 + 800 | bc`/g" file.txt
Run Code Online (Sandbox Code Playgroud)
但它正在用800到900之间的单个随机数替换892的所有出现次数.
输出文件 :-
temp11;djaxfile11;821
temp12;djaxfile11;821
temp13;djaxfile11;821
temp14;djaxfile11;821
temp15;djaxfile11;821
Run Code Online (Sandbox Code Playgroud)
你能帮忙纠正我的代码吗?提前致谢.