let variable a is your keyword list, then
let d a file
$ cat d
firstplace
secondplace
secondpot
a='first second place pot'
for o in $a; do
echo $o at the beginning of line is `grep -Poce '^'$o'' d` time; echo $o at the second following the previous found is `grep -Poce '^\w+?'$o'' d` time;echo
done
first at the beginning of line is 1 time
first at the second following the previous found is 0 time
place at the beginning of line is 0 time
place at the second following the previous found is 2 time
second at the beginning of line is 2 time
second at the second following the previous found is 0 time
pot at the beginning of line is 0 time
pot at the second following the previous found is 1 time
Rudi thanks.
your command works fine but as both files are huge grep fails i think.
can you give me something equivalent in awk?
---------- Post updated at 10:04 PM ---------- Previous update was at 09:58 PM ----------
i think awk is the solution as both files are huge but ah.awk you gave doesnt work..the script just keeps running.no output.
can you check if there is any error in the codes please?
---------- Post updated at 10:22 PM ---------- Previous update was at 10:04 PM ----------
for my ah.awk i tried adding #! /usr/bin/awk -f in the top line.
still didnt work.
thanks guys for helping.
---------- Post updated at 10:30 PM ---------- Previous update was at 10:22 PM ----------
i think the issue here is not grep.
i think the while read line doesnt work for big files.
how do i replace it with awk?
Hmm i am not a student so this isnt homework/coursework.
im learning these commands as i need to analyze some big project files.
kinda work for me.
is this ok?
Working through / analysing a huge data file with a huge pattern file will take its time no matter which tool you deploy, be it grep or awk or what have you; so, saying "doesn't work" may be premature. You should see the process working in e.g. top , piling up memory and / or processor time. Did any of the proposals given in here "work" (i.e. yield the desired / anticipated result) for smaller data sets and patterns? If yes, the logics are OK, and you have to address the performance question. Like e.g. split the patterns into smaller chunks.