I have a single source file which has multiple entries of this format:
some_id: some string
And a bunch of
.txt files in different folders that have strings that are identified by id
How do I parse the source file in a way so that each string in
.txt file which has
id matching one of source file be added a new parameter like so
id="some_id" some_param="some string"
which is taken from value of corresponding source file ID
- There can be multiple IDs in same file
- There are never duplicated IDs in any file
- They are never located on the same line
some_paramis a literal
- it does't matter where to add new
some_param="string"as long as it is on the same line and spaced out
apples: Apples are very tasty grapes: Grapes kind of ok trees: Gain mass from CO2 strawberry: Yummy
This is some plain text Toreplace id="apples" string contains The most vitamin-rich berry is id="strawberry"
And id="grapes" the
Given this sample, script should turn fruits/foo.txt into:
This is some plain text Toreplace id="apples" string contains some_param="Apples are very tasty" The most vitamin-rich berry is id="strawberry" some_param="Yummy"