Extract text between three single quotes
perl -l -0777 -ne "print for /'''(.*?)'''/gs" file
would extract (and print followed by a newline) the part between each pair of '''.
Beware that perl
slurps the whole file in memory before starting processing it so that solution may not be appropriate for very large files.
Try this, if you have gawk
or mawk
to your disposal:
gawk -v "RS='''" 'FNR%2==0' file
This assumes that there are no other '''
-s in the file.
Explanation: It sets the record separator to three single quotes, and prints if the record number is even.
Unfortunately, it won't work with all awk
implementations, as multi-character Record Separators are not part of POSIX awk
.
Not as nice as the awk answer but as you were originally using sed
/'''/{
s/.*'''//
:1
N
/'''/!b1
s/'''.*//
p
}
d
Or shorter as pointed out by glenn jackman in the comments (slightly changed)
/'''/,//{
//!p
}
d
Run as
sed -f script file
Output
This rule forbids throwing string literals or interpolations. While
JavaScript (and CoffeeScript by extension) allow any expression to
be thrown, it is best to only throw <a
href="https://developer.mozilla.org
/en/JavaScript/Reference/Global_Objects/Error"> Error</a> objects,
because they contain valuable debugging information like the stack
trace. Because of JavaScript's dynamic nature, CoffeeLint cannot
ensure you are always throwing instances of <tt>Error</tt>. It will
only catch the simple but real case of throwing literal strings.
<pre>
<code># CoffeeLint will catch this:
throw "i made a boo boo"
# ... but not this:
throw getSomeString()
</code>
</pre>
This rule is enabled by default.