bash - sed replace with eval -
what want do
replace: '1000' with: (a random number) shuf -i 500-1500 -n 1 shuf .. shall exectued every occurence of 1000
what i've tried
sed -i 's/1000/$(shuf -i 500-1500 -n 1)/g' but takes eval string
it happens because single quotes escape meaning of $ , command substitution not occurring.
solution use double quotes
sed -i "s/1000/$(shuf -i 500-1500 -n 1)/g" the double quotes retains special meaning of
$, other special characters.
to replace each occurrence different values shuf, can loop on file using basic while , replace string as
while read line echo "$line" | sed -i "s/1000/$(shuf -i 500-1500 -n 1)/g" >> output_temp done mv output_temp original_file - the
whileloop reads each line file , replaces them. mvreplaces original file temp file.
Comments
Post a Comment