What I'm trying to do is to search through a list of files, and output the filename, followed by the lines that matched the pattern.
I'm matching the string "letters.moreletters" in any one of searched files, and the output I'm trying to get is:
program_1.txt
10 dsdsd sdsd dsd dsdsd.dsdsd dsdsdsd sdsd
12 sasas sasas sasas sasas.sasas sasas sasas
program_2.txt
15 ewewe ewewe ewewe ewewe.ewew ewewe
25 fdfdf fdfdf fdfdf fdfdf.fdfdf fdfdf dfdfdf fdfdf
So far I've got
grep -n '[A-Za-z0-9_]\.[A-Za-z_]' *.txt | awk -F: '{print $1"\n";print $2"\t"$3}'
(apologies if thats not the exact syntax, I can't test at the moment) which outputs :
program_1.txt
10 dsdsd sdsd dsd dsdsd.dsdsd dsdsdsd sdsd
program_1.txt
12 sasas sasas sasas sasas.sasas sasas sasas
program_2.txt
15 ewewe ewewe ewewe ewewe.ewew ewewe
program_2.txt
25 fdfdf fdfdf fdfdf fdfdf.fdfdf fdfdf dfdfdf fdfdf
...which is nearly there, but I don't know UNIX well enough to know if I'm going in the wrong direction. The other problem with the above command is it assumes the : will be used for the grep delimiter, and that no more will appear.
I basically want awk to take the first, second and the rest of the string, and dedupe every third line.
Any help is much appreciated, as there appears to be so many ways to accomplish these things, but putting them to practise is another story.