Yash
Yash

Reputation: 1018

Replacing placeholder with multiple lines

I have a template that looks like:

<mydata>
<tag1> 
<tag2> etc.
DATAHERE
</mydata>

I want to run a query on a DB and fetch a number of records and place them one below the other in the file at the place where there is the string DATAHERE.

My records are already fetched in mydata.txt. How do i replace the single line of DATAHERE ? I do not want to hardcode the number of lines in the template to skip. DATAHERE is my only marker.

Upvotes: 0

Views: 236

Answers (1)

potong
potong

Reputation: 58578

This might work for you (GNU sed):

sed -e '/DATAHERE/{r dataFile' -e 'd}' file

Focus on the line DATAHERE and read the file dataFile then delete the current line.

Upvotes: 3

Related Questions