Reputation:
I am trying to extract a sub-string from each line in a file between 2 groups of characters :
each line in the input file is :
https://github.com/myname/repo1 | GitHub - repo description
https://github.com/myname/repo2 | GitHub - repo description
https://github.com/myname/repo3 | GitHub - repo description
....
https://github.com/myname/repoN | GitHub - repo description
I extract the sub-string between "https://github.com/" and " | GitHub" to get :
myname/repo1
myname/repo2
myname/repo3
...
myname/repoN
And I use GNU grep. :
grep -nPo 'github.com\/\K.*?(?= \|)' ~/Desktop/forksonGithub.txt
This displays the correct list in the console with line number
1:myname/repo1
2:myname/repo2
3:myname/repo3
...
4:myname/repoN
how can I get this list in an output file without the lin numbers ? thanks for feedback
Upvotes: 1
Views: 47
Reputation: 7164
The option -n
is responsible for the line numbers. You just need to remove it:
grep -Po 'github.com\/\K.*?(?= \|)' ~/Desktop/forksonGithub.txt
myname/repo1
myname/repo2
myname/repo3
...
myname/repoN
Upvotes: 1