I have a need to use a number contained in each line of a text file as a variable in a repeat remove task on that line.
Specifically, per line; (1) The column position of the START of the number to be selected is known, but not the end. i.e it can be of any digit length, BUT is ended with a space. (2) Take this number and use it in a repeat remove task across the whole line. I would like to remove ALL text between foo and bar, similar to foo.*bar the number of times given in (1). foo and bar are repeated in pairs (foo first) the number of times in (1), and can be different per line.
Does anyone know how to do this with SED please. Keen, through SED, to get a way to control sed -i 's/foo.*bar//g' type examples I keep seeing, which removes ALL text from the first foo to the last bar, inclusive. We need all text between foo and bar, for every foo bar that appears.
UPDATE: Consider a file, example.txt
someText 1 foo someOtherText bar someOtherOtherText
someText 2 foo someOtherDiffText bar x x x foo text bar
We need to return;
someText
someText x x x
The numbers tell us how many time the pairing foo-bar, with text between it, appears, and range from 1 to 100s
Kind Regards
HS