I have a text file, and would like to append a counter to a number of different strings of interest. An example infile:
string_of_interest
abcd
efgh
another_string_of_interest
ijkl
abcd
another_string_of_interest
mnop
wxyz
string_of_interest
ijkl
wxyz
another_good_string
abcd
efgh
another_string_of_interest
As you can see there are multiple strings to ignore, some of which might repeat, but I only want to count repeats for a subset of strings to produce an outfile like this:
string_of_interest_1
abcd
efgh
another_string_of_interest_1
ijkl
abcd
another_string_of_interest_2
mnop
wxyz
string_of_interest_2
ijkl
wxyz
another_good_string_1
abcd
efgh
another_string_of_interest_3
Note the counter is appended as part of each string using snake case.
I've fumbled around with sed and awk to try, but I'm so novice I'm nowhere close yet. Any recommendations?
sedis notoriously bad at counting, you you probably want to useawkor some other language with support for arithmetics.AandA_1(orA_n, for some positive integern)?t.*eas the "string" and include lines withtheandat.*enin your input as well as the real target stringfoo_t.*e_bar.