I need to generate new files by modifying a string in an existing file.
I have a text file called newheader.txt, it looks like this:
@RG ID:$FILENAME SM:$FILENAME
I also have a text file called filenames.txt that looks like this:
ZF-150-81_S49
ZF-150-82_S55
ZF-150-83_S59
I would like to have a for loop to go through filenames.txt one line at a time and replace the $FILENAME string in newheader.txt with the line in filenames.txt and make each of these into a new .txt file with that line in the title.
This would create three output files. For example the first output file would be called ZF-150-81_S49.header.txt and inside it should look like this:
@RG ID:ZF-150-81_S49 SM:ZF-150-81_S49
In other words something like:
for $FILENAME in filename.txt; do replace $FILENAME in newheader.txt > $FILENAME.header.txt ; done
I have done bash for loops but not where it requires replacing a string in a text file. Happy for other solutions such as perl if this makes more sense. Thanks for your assistance.
sedis the generic replace command.