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
FILESOURCE= my .txt file to read
TEXTTOSEARCH= string to search
TEXTTOREPLACE= 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.