I have a regular expression that has several matches in a textfile.
I want to copy only the the matches to a second file. I dont want to copy the lines that contain the matches: I only want the matched text.
I dont find a way to do this in notepad++ (only copies complete lines, not only the matches). Also not in Visual Studio search.
Is there a way to copy only matches? Maybe in grepp or sed?
You can do it with both. Lets say I have a following file –
Sample file:
And I want to capture
only numbersfrommyfileUsing
sed:With
sedyou can use the combination of-nandpoption along withgrouped pattern.Test:
You can simply re-direct this to another file.
Using
grep:You can use either –
or
From the man page:
Test:
You can simply re-direct this to another file.
Note: Obviously these are simple examples but it conveys the point.