I have files in which I am storing some credentials, I want shell script to read that file and check if current cred matches searched string, replace that at that location only.
I tried below code but it always append and does not even replace string.
cat $FILESOURCE | sed -e "s/$TEXTTOSEARCH/$TEXTTOREPLACE/g" >> $FILESOURCE
where
FILESOURCE= my .txt file to readTEXTTOSEARCH= string to searchTEXTTOREPLACE= text to replace
Note: I don't want to mess up existing file, instead it just open file for reading check if searched string found, then replace it, if not found dont do anything to file.
$TEXTTOSEARCH) cannot contain the/or any characters that have a special meaning in the context of regular expressions?