Based on the contents of the manual, to find all strings in a file that match the pattern endpoint = '...', where ... represents the part you want to extract, you can use the grep command with Perl regular expression support, which can be enabled with the -P option.
Here is an example command that will find all occurrences of that pattern and output only the matched parts (the ... inside the single quotes):
bash
grep -oP "endpoint = '\K[^']+(?=')" filename
Let's break down the command:
grep is the command to search through the file.
-o is an option that tells to output only the matched parts of the pattern, not the entire line.
User
grep: invalid option -- P
I'm using ugrep, not grep
Assistant
My apologies for the confusion. In the case of ugrep, which does not support the -P option for Perl regex like grep, you would have to use the extended regular expressions (EREs) to match the pattern you're interested in.
Here's an example command using ugrep to find all the strings that match the pattern endpoint = '...' and to extract just the '...' part:
-o only outputs the matched parts of the line, similar to grep.
Having this manual help me find all strings in file which looks like this:
endpoint = '...'
I need to get only ... part
Options and arguments:
code
-E, --extended-regexp
Interpret patterns as extended regular expressions (EREs). This is
the default.
-e PATTERN, --regexp=PATTERN
Specify a PATTERN used during the search of the input: an input
line is selected if it matches any of the specified patterns.
Note that longer patterns take precedence over shorter patterns.
This option is most useful when multiple -e options are used to
specify multiple patterns, when a pattern begins with a dash (`-'),
to specify a pattern after option -f or after the FILE arguments.
-G, --basic-regexp
Interpret patterns as basic regular expressions (BREs), i.e. make
ugrep behave as traditional grep.
-N PATTERN, --neg-regexp=PATTERN
Specify a negative PATTERN used during the search of the input: an
input line is selected only if it matches the specified patterns
unless it matches the negative PATTERN. Same as -e (?^PATTERN).
Negative pattern matches are essentially removed before any other
patterns are matched. Note that longer patterns take precedence
over shorter patterns. This option may be repeated.
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression using PCRE2.
Note that Perl pattern matching differs from the default grep POSIX
pattern matching.
-w, --word-regexp
The PATTERN is searched for as a word, such that the matching text
is preceded by a non-word character and is followed by a non-word
character. Word characters are letters, digits and the
underscore. With option -P, word characters are Unicode letters,
digits and underscore. This option has no effect if -x is also
specified. If a PATTERN is specified, or -e PATTERN or -N PATTERN,
then this option has no effect on -f FILE patterns to allow -f FILE
patterns to narrow or widen the scope of the PATTERN search.
-x, --line-regexp
Select only those matches that exactly match the whole line, as if
the patterns are surrounded by ^ and $. If a PATTERN is specified,
or -e PATTERN or -N PATTERN, then this option has no effect on
-f FILE patterns to allow -f FILE patterns to narrow or widen the
scope of the PATTERN search.
Related options:
code
--filter-magic-label=[+]LABEL:MAGIC
Associate LABEL with files whose signature "magic bytes" match the
MAGIC regex pattern. Only files that have no filename extension
are labeled, unless +LABEL is specified. When LABEL matches an
extension specified in --filter=COMMANDS, the corresponding command
is invoked. This option may be repeated.
--help [WHAT], -? [WHAT]
Display a help message on options related to WHAT when specified.
In addition, `--help regex' displays an overview of regular
expressions, `--help globs' displays an overview of glob syntax and
conventions. `--help fuzzy' displays details of fuzzy search with
option -Z and `--help format' displays a list of --format fields.
-M MAGIC, --file-magic=MAGIC
Only files matching the signature pattern MAGIC are searched. The
signature "magic bytes" at the start of a file are compared to
the MAGIC regex pattern. When matching, the file will be searched.
When MAGIC is preceded by a `!' or a `^', skip files with matching
MAGIC signatures. This option may be repeated and may be combined
with options -O and -t to expand the search. Every file on the
search path is read, making searches potentially more expensive.
Extended regular expression syntax overview (excludes some advanced patterns):
pattern matches pattern removes special meaning
. any character except \n . escapes . to match .
a the character a \Q...\E the literal string ...
ab the string ab --------------------------------------
a|b a or b
a* zero or more a's pattern special characters
a+ one or more a's ---------- --------------------------
a? zero or one a \f form feed
a{3} 3 a's \n newline
a{3,} 3 or more a's \r carriage return
a{3,7} 3 to 7 a's \R any Unicode line break
a*? zero or more a's lazily \t tab
a+? one or more a's lazily \v vertical tab
a?? zero or one a lazily \X any character and \n
a{3}? 3 a's lazily \cZ control character ^Z
a{3,}? 3 or more a's lazily \0 NUL
a{3,7}? 3 to 7 a's lazily \0ddd octal character code ddd
-------------------------------------- \xhh hex character code hh
\x{hex} hex Unicode code point
pattern character classes \u{hex} hex Unicode code point
[abc-e] one character a,b,c,d,e
[^abc-e] one char not a,b,c,d,e,\n pattern anchors and boundaries
[[:name:]] one char in POSIX class: ---------- --------------------------
alnum a-z,A-Z,0-9 ^ begin of line anchor
alpha a-z,A-Z $ end of line anchor
ascii ASCII char \x00-\x7f \b word boundary (-P)
blank space or tab \B non-word boundary (-P)
cntrl control characters < start word boundary (-P)
digit 0-9 > end word boundary (-P)
graph visible characters (?=...) lookahead (-P)
lower a-z (?!...) negative lookahead (-P)
print visible chars and space (?<=...) lookbehind (-P)
punct punctuation characters (?<!...) negative lookbehind (-P)
space space,\t,\n,\v,\f,\r --------------------------------------
upper A-Z
word a-z,A-Z,0-9,_ pattern grouping
xdigit 0-9,a-f,A-F ---------- --------------------------
\p{class} one character in class (...) capturing group (-P)
\P{class} one char not in class (...) non-capturing group
\d a digit (?:...) non-capturing group
\D a non-digit (?...) capturing, named X (-P)
\h a space or tab \1 matches group 1 (-P)
\H not a space or tab \g{10} matches group 10 (-P)
\s a whitespace except \n \g{X} matches group name X (-P)
\S a non-whitespace (?#...) comments ... are ignored
\w a word character --------------------------------------
\W a non-word character
-------------------------------------- (-P): pattern requires option -P
Option -U disables full Unicode pattern matching: non-POSIX Unicode character
classes \p{class} are disabled, ASCII, LATIN1 and binary regex patterns only.
Option --bool adds the following operations to regex patterns a' and b':
pattern operation pattern operation
(...) grouping "..." the literal string ...
-a logical not a NOT a locical not a
a|b logical a or b a OR b logical a or b
a b logical a and b a AND b locical a and b
Listed from the highest level of precedence to the lowest, NOT is performed
before OR and OR is performed before AND. Thus, -x|y z' is ((-x)|y) z'.
Spacing with --bool logical operators and grouping is recommended. Parenthesis
become part of the regex sub-patterns when nested and when regex operators are
directly applied to a parenthesized sub-expression. For example, ((x y)z)' matches x yz' and likewise ((x y){3} z)' match three x y' and a `z'.
The default is to match lines satisfying the --bool query. To match files,
use option --files with --bool. See also options --and, --andnot, --not.
Option --stats displays the options and patterns applied to the matching files.
grep
-P enables Perl regular expression support, which allows for more complex patterns.
"endpoint = '\K[^']+(?=')" is the pattern:
endpoint = ' matches the literal string "endpoint = '"
\K is used to reset the start of the reported match. Everything matched before \K will not be included in the output.
[^']+ is a Perl regex that matches one or more characters that are not a single quote, capturing the string inside the quotes.
(?=') is a positive lookahead assertion that checks for a closing single quote without including it in the match.
filename should be replaced with the actual name of your file.
Run this command in your terminal, replacing filename with the path to your actual file. The output will be all the string contents from patterns in the file that match the specified format, exclusive of the surrounding endpoint = ' and trailing '.
"endpoint = '[^']+'" is the pattern to match.
endpoint = ' matches the literal string.
[^']+ matches one or more characters that are not a single quote.
filename is where you place the actual name of your file.
sed is then used to process the output further:
s/endpoint = '\([^']\+\)'/\1/ substitutes the whole matched string with just the part within the single quotes, using capture groups.
Please note that if ugrep supports a more concise way to output only the matched group (like grep with -P), you could use that instead. If it does, you would not need to pipe the output through sed. Since the ugrep manual you provided does not show a direct option for this, we use sed as a post-processing step to extract the desired output.
Replace filename with your actual file name and run this command in your terminal to see the extracted strings.