I receive a huge textfile generated with find.
The contents of the generated textfile are a file-referenes with full path, i.e.:
(filenames and paths are kinda random, so I can't start always at position n from the begining or the end of a line)
I need to
grep this textfile for a specific pattern, write the results (which needs to be a complete line for a match) into a new (sorted with
sort) file, but also need to ignore any match which is not a filename.
So, with my example-lines above, I have a search pattern "dir1" and the result must be a new file containing those lines:
My attempts with
sort -f -u $textfile | grep -i $pattern > $newfile were not successful, because grep has a match too when the directory contains the pattern, which will result in a "false" match for
I read in
grep manual that regex is possible with option
-G but could'nt fiddle out any way to grep only in the filenames part of a line.