sed String Replace

I have this file and variable on my machine

$cat /tmp/disk.tmp
check_disk.pl -H localhost -D ARG1 -w 75 -c 90
$echo $_ARG1
/,/opt,/tmp,/usr,/var,/boot,/dev/shm

how do I replace the string ARG1 in my file (disk.tmp) with the value of my variable _ARG1 and placing them inside quotes while still having those other charaters on it such it will look like below:

check_disk.pl -H localhost -D "/,/opt,/tmp,/usr,/var,/boot,/dev/shm" -w 75 -c 90

Any help would be appreciated. Been trying different way already with sed but nothing works. :frowning:

Try

sed "s|ARG1|\"$_ARG1\"|" file

GNU sed and BSD sed have a -i option for inline editing. Otherwise, redirect the output to a new file and if successful replace original with the new content..

sed s#ARG1#\"$_ARG1\"# file
check_disk.pl -H localhost -D "/,/opt,/tmp,/usr,/var,/boot,/dev/shm" -w 75 -c 90

Wow. Both works perfectly. Thank you so much!

Note: it is best to use quotes around the sed command argument, otherwise strange characters or spaces thay may be contained in $_ARG1 will break the command..