Wednesday, May 15, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1364  / 2 Years ago, sun, may 29, 2022, 1:17:21

I have a file with words, one word per line, which I now want to change so that is becomes a .sh-file with an egrep-search string for each word. The search string I want in the end looks like this:





`egrep -wi '|WORD..nn' stats_all.txt > WORD_frekvens.txt`


My word file looks like this:



$ more -10 word_file.txt
anakonda
ord
tröja
bord
glas
pension
larm
risk
försening
rapport


I have tried to do this with the following string:



sed -e 's/(.*)/egrep -wi '''|1..nn''' stats_all.txt > 1_frekvens.txt/' word_file.txt | more


But it gives the output:



_frekvens.txt_all.txt > WORD


Why doesn't it work to use the 1 here? It seems to be this part that's the problem, as it works if I exchange it for a word.



Anything I write after 1 ends up writing over the content of 1, i.e. "WORD". If I write something only before 1 it works fine.



Very grateful for any help.


More From » command-line

 Answers
5

You can also process your list of words with the following perl command:



$ perl -ne 's/s*$//; print "egrep -wi 047|${_}..nn047 stats_all.txt > ${_}_frekvens.txt
"' word_file.txt


Note that I'm using 047 to avoid escaping ' (single quote).



With a dummy word_file.txt:



foo
bar


The output is:



egrep -wi '|foo..nn' stats_all.txt > foo_frekvens.txt
egrep -wi '|bar..nn' stats_all.txt > bar_frekvens.txt

[#19765] Sunday, May 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
algicuade

Total Points: 317
Total Questions: 89
Total Answers: 106

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;