22
votes
Accepted
grep command fails with out-of-memory error
If you look at the code of the GNU implementation of grep for what happens when invoked as grep -Fxvf file1 file2, you'll see it:
reads the whole contents of file1 in memory
deduplicates the lines in ...
11
votes
Accepted
Inconsistent “unzip -l … | grep -q …” results with pipefail
It basically looks like another case of https://stackoverflow.com/questions/19120263/why-exit-code-141-with-grep-q, which I found by looking into the return status that I was getting (141).
In some ...
9
votes
Accepted
AWK search for multiple patterns in a file
if
awk '
!a && /writeback error on sector/ {a=1}
!b && /blk_update_request: I\/O error/ {b=1}
!c && /xfs_do_force_shutdown/ {c=1}
success = a + ...
8
votes
Inconsistent “unzip -l … | grep -q …” results with pipefail
You can do:
mp3_or_flac_in_archive() (
archive=${1?No archive given.}
set -o pipefail
bsdtar tf - < "$archive" | grep -iE '[^/]\.(flac|mp3)$' > /dev/null
)
For grep to read the ...
3
votes
gnu grep multiple filters in one regex
The command you can use is:
cut -f1 -d: .pgpass | grep -E '^FISP.*(CDS|TAP).*PGS401'
The will search for (regex) ^FISP.*CDS.*PGS401 or ^FISP.*TAP.*PGS401
Here is the result of execution, based on the ...
3
votes
Inconsistent “unzip -l … | grep -q …” results with pipefail
If it's important for the left-hand side command to finish, you could run grep without -q and just redirect the output to /dev/null. The exit status should be the same (but of course grep does some ...
2
votes
AWK search for multiple patterns in a file
Your code is testing for all 3 regexps matching in one record but by default awk treats each input line as a separate record so one option would be to have awk treat the whole input file as a record, ...
2
votes
Accepted
gnu grep multiple filters in one regex
I'd try using \ to flip the "special" state* of your ()|s. You can do it like this:
grep '^FISP\(CDS\|TAP\)PGS401'
"special" state: prefacing a character with \ flips it from &...
2
votes
Accepted
To get the highest value after the hyphen (-) from the list
If the input is sorted like that, with the "highest" value for each initial (before the dash) part first, then this can be reduced to just printing the line if the initial part is different ...
2
votes
How does pattern matching work in grep for accented characters (eg. á, è, ò)
I think I found a solution for your problem. The issue is that there are many different flavours or dialects of Regex: Basic (BRE), Extended (ERE), and Simple (SRE). grep also understands PCRE, which ...
2
votes
To get the highest value after the hyphen (-) from the list
There is a "famous" AWK idiom for selecting lines only where a field value only appears for the first time.
awk -F- '!seen[$1]++' file
seen is an associative array, keyed by the value of ...
1
vote
To get the highest value after the hyphen (-) from the list
With GNU sort or compatible:
$ <your-file sort -t- -k2rn | sort -sut- -k1,1rg
4.1-1
4.0-2
3.14-2
3.13.-1
3.12
3.11-2
1
vote
How to use grep to get the matching part only, without introducing extra newlines
Using Raku (formerly known as Perl_6)
~$ raku -ne 'put join "", m:g/ ban <[a..z]>* /;' file
#OR
~$ raku -ne 'put join "", m:g/ ban <alpha>* /;' file
Raku is a ...
1
vote
grep for capital words
Using Raku (formerly known as Perl_6)
Translating Perl answers herein into Raku:
~$ raku -ne '.put for m:g/ \w* <[A..Z]>+ \w* /;' file
#OR:
~$ raku -ne '.put for m:g/ \w* <:Lu>+ \w* /;' ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
grep × 5058awk × 1104
sed × 963
text-processing × 849
regular-expression × 725
bash × 715
linux × 567
shell-script × 479
find × 366
shell × 348
command-line × 235
search × 151
scripting × 135
files × 129
pipe × 124
cut × 96
string × 90
perl × 81
logs × 77
xargs × 69
macos × 68
ls × 67
wildcards × 64
sort × 63
tail × 63