Bash script to replace markers in file
Hi,
I have a file of the form (testfile.txt):
here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here $file1.txt$ Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more $file2.txt$ Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here Some text in here and more here $file3.txt$
I also have text files with names of the form "filen.txt" which have Markdown tables in them.
-------------------- age weight sex ----- -------- ----- 15 45 m 20 56 f 25 65 f 30 72 m --------------------
I want to run a script to search for all the markers, and "inject" the relevant table at the marker by opening the file of that name in the same directory and doing a replace with it.
I have the "shell" of the script (sorry about the pun). I cannot however get it to do the injecting part.
I've tried Awk, sed, perl....you name it.
The script so far is:
#!/bin/bash line="" places="" while read -r line; do places=$(awk '/\$*\$/ { print $0 }') done < testfile.txt cp testfile.txt try.txt echo "$places" | { while read line; do strip=$(echo $line | sed 's/^\$//') strip=$(echo $strip | sed 's/\$$//') curtext=$(cat $strip) cat try.txt | { while read line; do # Something in here to take $strip add a $ at each end and replace #+with $curtext done } done }
I would really appreciate some help to fill in the area where the comment is. I am successfully getting all the other bits to work.
Many thanks
Mike