Using sed - search and replace
I'm using sed in a bash script to search and replace and the correct syntax is alluding me.
Specifically I need the script to locate a line in a text file and replace the match. Below is my sample including the file to edit (source) and what I'd like the resulting file to look like. So far, I've not been able to expand ARG before writing it to the file. thanks in advance - SeeBee #!/bin/bash ARGS='--channelfile /etc/mail/SA/sare-sa-update-channels.txt --gpgkey 856AA88A' # Below line is the problem line. sed -i 's/SAUPDATEARGS=""/SAUPDATEARGS="${ARGS}"/' update_sare # eof Source file: update_sare # # spamassassin settings # SAUPDATEARGS="" Desired output: update_sare # # spamassassin settings # SAUPDATEARGS="--channelfile /etc/mail/SA/sare-sa-update-channels.txt --gpgkey 856AA88A" |
Quote:
Code:
sed -i 's/SAUPDATEARGS=""/SAUPDATEARGS='"${ARGS}"'/' update_sare |
Quote:
Code:
sed -i "s/SAUPDATEARGS=\"\"/SAUPDATEARGS=\"${ARGS}\"/" update_sare Code:
sed -i 's/SAUPDATEARGS=""/SAUPDATEARGS="'"${ARGS}"'"/' update_sare |
Quote:
|
thanks for the responses and the explanations. I tried options and kept at it. I finally figured out that the / in the ARGS was the issue and substituted the ^ symbol.
Works great now. thank you for the tips, they helped me get the solution! ARGS="--channelfile /etc/mail/SA/sare-sa-update-channels.txt --gpgkey 856AA88A" sed -i 's^SAUPDATEARGS=""^SAUPDATEARGS="'"${ARGS}"'"^' /tmp/update_sare |
Please mark as SOLVED once you have a solution.
|
All times are GMT -5. The time now is 09:18 PM. |