I need to replace STUDENT (if found in the file FILENAME) with REPLACE.I've been searching for a couple hours now,so it's time for a question. What is the correct syntax of sed to do it ?
My best attempt :
Let me know (answer this comment and ping me with @terdon) if the duplicate's answers don't solve your issue.
– terdonSep 10 '21 at 15:36
@terdon, My problem is not solved yet. The problem is that the output is not going to file so something must be wrong with sed. Since you sowed me that post, I changed sed to : sed "s/$STUDENT/$REPLACE/" $FILENAME $FILENAME ,and it's working better but when STUDENT is found it is not changed in the file. When I trie to append it using FILENAME >> FILENAME at the and of sed, it duplicates the whole content of the file. If I use > instead , everything in the output file gets deleted instead of overwriting just the one spot where STUDENT is located.
– JohnSep 10 '21 at 15:49
Please [edit] your question and add i) an example input and ii) the output you are expecting. sed doesn't change the file by default, it just prints the results to the terminal. If you want to change the original file, you need -i.
– terdonSep 10 '21 at 16:15
@terdon
) if the duplicate's answers don't solve your issue. – terdon Sep 10 '21 at 15:36sed
doesn't change the file by default, it just prints the results to the terminal. If you want to change the original file, you need-i
. – terdon Sep 10 '21 at 16:15