Have to read one file say sourcefile containing several words and having another folder containing several files.
Now read the first word of Sourcefile & search it into the folder consisting sevral files, and create another file with result. We hhave to pick the filename of the file in which we have that word and the linenumber.
Outputfile format:
Filename Word Linenumber
Samething we have to do for all words. We can have same word in a single file multiple times and need to pick all line numbers.
---------- Post updated at 03:04 PM ---------- Previous update was at 01:32 PM ----------
Guys kindly help me to get the resolution. I am trying hard.
$ cat f2
jfdklsjfkldsq
jfdklsjfkldsq
toto
jfdklsjfkldsq
toto titi toto titi
jfdklsjfkldsq
titi
jfdklsjfkldsq
$ cat f3
toto
jfdklsjfkldsq
toto titi toto titi
jfdklsjfkldsq
titi
$ nawk 'NR==FNR{a[++c]=$0;next}{for(i in a) {if (match($0,a)) print FILENAME,a,FNR };next}' f1 f2 f3
f2 toto 3
f2 toto 5
f2 titi 5
f2 titi 7
f3 toto 1
f3 toto 3
f3 titi 3
f3 titi 5
also
$ nawk 'NR==FNR{a[++c]=$0;next}{d=1;do{if (match($0,a[d])) print FILENAME,a[d],FNR}while(++d in a);next}' f1 f2 f3
f2 toto 3
f2 toto 5
f2 titi 5
f2 titi 7
f3 toto 1
f3 toto 3
f3 titi 3
f3 titi 5