Thanks for the replies, I think David's solution is how i'll have to proceed. I've tried throwing the string into the the original file but have not managed to do this yet from online sources.
Code:
ed -s infile.txt <<< printf '%s\n' '/# list/a' "$insert" '.'
I will need to perform a global replace which may require slashes. sed wont do this without some help that i dont want to have to have on the front end (i.e. i dont want to ask the user to type \/), can ed do this? or is there a way for sed to accept a / on face value?
The coding below may look strange; the purpose of all of this is to update the very same script that you are using (opening up the updated file and shutting down the original). As such i have some variables at the top of the script that i will replace and write to a new version of the script.
Code:
name=/users/fred
read -p "Enter the directory:" newname
oldname=$name
if [[ ${newname} == "" ]]; then
newname=${oldname}
fi
sed 's/'${oldname}'/'${newname}'/g' file_v1.txt > file_v2.txt
thanks
---------- Post added 05-13-13 at 08:47 AM ----------
Thanks for the replies, I think David's solution is how i'll have to proceed. I've tried throwing the string into the the original file but have not managed to do this yet from online sources.
Code:
ed -s infile.txt <<< printf '%s\n' '/# list/a' "$insert" '.'
I will need to perform a global replace which may require slashes. sed wont do this without some help that i dont want to have to have on the front end (i.e. i dont want to ask the user to type \/), can ed do this? or is there a way for sed to accept a / on face value?
The coding below may look strange; the purpose of all of this is to update the very same script that you are using (opening up the updated file and shutting down the original). As such i have some variables at the top of the script that i will replace and write to a new version of the script.
Code:
name=/users/fred
read -p "Enter the directory:" newname
oldname=$name
if [[ ${newname} == "" ]]; then
newname=${oldname}
fi
sed 's/'${oldname}'/'${newname}'/g' file_v1.txt > file_v2.txt
thanks