GNU bug report logs -
#49698
Search for URL containing certain word
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 49698 in the body.
You can then email your comments to 49698 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-grep <at> gnu.org
:
bug#49698
; Package
grep
.
(Thu, 22 Jul 2021 19:41:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Julius Hamilton <julkhami <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-grep <at> gnu.org
.
(Thu, 22 Jul 2021 19:41:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hey,
I'm new to grep so I'd love any tips on how to search for text in the
following way.
I'd like to find a certain URL that is somewhere in a large text file. I
would like to find it by specifying "a URL which contains word X somewhere
within it", or even "a URL which is located within 3 lines of the word X".
I'd like to copy that URL and then write it to the top of the file.
I am considering doing this with Vim search commands, yet the underlying
regex would be the same, so I think this would be a good place to ask.
How would you do this with grep? Or a similar tool?
Thanks very much,
Julius
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-grep <at> gnu.org
:
bug#49698
; Package
grep
.
(Thu, 22 Jul 2021 23:49:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 49698 <at> debbugs.gnu.org (full text, mbox):
Julius Hamilton writes:
> Hey,
>
> I'm new to grep so I'd love any tips on how to search for text in the
> following way.
>
> I'd like to find a certain URL that is somewhere in a large text file. I
> would like to find it by specifying "a URL which contains word X somewhere
> within it", or even "a URL which is located within 3 lines of the word X".
>
> I'd like to copy that URL and then write it to the top of the file.
>
> I am considering doing this with Vim search commands, yet the underlying
> regex would be the same, so I think this would be a good place to ask.
>
> How would you do this with grep? Or a similar tool?
Hi Julius,
I'm not sure this is quite what the grep bug interface is intended for. :-)
egrep -C 3 X largefile | egrep -o "$URL_REGEX"
where URL_REGEX is a regular expression matching URLs with any
particular level of specificity that you want, with a very simple case
being something like
https?://[^, ]+
As we might have recently discussed on help-bash (?), Unix doesn't have
a super-nice built-in notion of "writing to the top of a file" and you
would normally need to write the matches, followed by the original file,
to a temporary file. Something like
set -e
temp=$(mktemp)
egrep -C 3 X largefile | egrep -o "$URL_REGEX" > $temp
cat largefile >> $temp
mv $temp largefile
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
You have taken responsibility.
(Fri, 23 Jul 2021 15:25:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Julius Hamilton <julkhami <at> gmail.com>
:
bug acknowledged by developer.
(Fri, 23 Jul 2021 15:25:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 49698-done <at> debbugs.gnu.org (full text, mbox):
Not a bug, so closing the bug report.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 21 Aug 2021 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 2 years and 220 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.