Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you need to match content without including it in the result (must match <code>name="</code> but it's not part of the desired result) some form of zero-width matching or group capturing is required. This can be done easily with the following tools:</p> <h3>Perl</h3> <p>With Perl you could use the <code>n</code> option to loop line by line and print the content of a capturing group if it matches:</p> <pre><code>perl -ne 'print "$1\n" if /name="(.*?)"/' filename </code></pre> <h3>GNU grep</h3> <p>If you have an improved version of grep, such as GNU grep, you may have the <code>-P</code> option available. This option will enable Perl-like regex, allowing you to use <code>\K</code> which is a shorthand lookbehind. It will reset the match position, so anything before it is zero-width.</p> <pre><code>grep -Po 'name="\K.*?(?=")' filename </code></pre> <p>The <code>o</code> option makes grep print only the matched text, instead of the whole line.</p> <h3>Vim - Text Editor</h3> <p>Another way is to use a text editor directly. With Vim, one of the various ways of accomplishing this would be to delete lines without <code>name=</code> and then extract the content from the resulting lines:</p> <pre><code>:v/name=/d :%s/\v.*name\="([^"]+)".*/\1 </code></pre> <hr> <h3>Standard grep</h3> <p>If you don't have access to these tools, for some reason, something similar could be achieved with standard grep. However, without the look around it will require some cleanup later:</p> <pre><code>grep -o 'name="[^"]*"' filename </code></pre> <hr> <h3>A note about saving results</h3> <p>In all of the commands above the results will be sent to <code>stdout</code>. It's important to remember that you can always save them by piping it to a file by appending:</p> <pre><code>&gt; result </code></pre> <p>to the end of the command.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload