Skip to main content
Planned maintenance impacting Stack Overflow and all Stack Exchange sites is scheduled for Monday, September 16, 2024, 5:00 PM-10:00 PM EDT (Monday, September 16, 21:00 UTC- Tuesday, September 17, 2:00 UTC). The email/password authentication method will be unavailable for logging in and registering. Read more here
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 ...
Stéphane Chazelas's user avatar
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 ...
Alice M.'s user avatar
  • 389
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 + ...
Stéphane Chazelas's user avatar
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 ...
Stéphane Chazelas's user avatar
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 ...
Romeo Ninov's user avatar
  • 18.1k
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 ...
ilkkachu's user avatar
  • 142k
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, ...
Ed Morton's user avatar
  • 33.1k
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 &...
waltinator's user avatar
  • 5,498
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 ...
ilkkachu's user avatar
  • 142k
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 ...
Ricardo's user avatar
  • 151
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 ...
glenn jackman's user avatar
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
Stéphane Chazelas's user avatar
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 ...
jubilatious1's user avatar
  • 3,505
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* /;' ...
jubilatious1's user avatar
  • 3,505

Only top scored, non community-wiki answers of a minimum length are eligible