I have a list of phrases in a single file ( "phrases
" ), each being on its own line.
I also have another file, which contains a list of words, each on a line ("words
").
I wish to append an asterisk at the end of every phrase in "phrases
", which begins with a word listed in "words
".
For example:
File "phrases
":
gone are the days
hello kitty
five and a half
these apples are green
File "words
":
five
gone
Expected result in "phrases
" after the operation:
gone are the days *
hello kitty
five and a half *
these apples are green
What I have done so far is this:
parallel -j0 -a words -q perl -i -ne 'print "$1 *" if /^({}\s.*)$/' phrases
But this truncates the file and sometimes (not always) gives me this error:
Can't remove phrases: No such file or directory, skipping file.
Because the edits will be made in concurrently, my intention is for it to search and replace ONLY those lines which start with the word while leaving the other ones intact. Otherwise the parallel
concurrent execution will overwrite each other.
I am open to other concurrent methods as well.