0

I am attempting to list files that don't end in gz

I have a minimal working example:

ll chrX_PAR1.phased.vcf.gz | grep -v gz$

should show empty, but the file still shows, with or without quotes.

I have also tried

ll chrX_PAR1.phased.vcf.gz | grep -vP gz$

but this fails as well.

ll chrX_PAR1.phased.vcf.gz | grep -vE 'gz$'

also fails.

I have read Correct regex not working in grep and Anchors not working with grep but I don't see anything there that would solve this problem.

con
  • 109
  • Is your question about this specific grep example or about listing the files, because !(*.gz) would expand to the list of non-hidden filenames that don't end in .gz in bash if you enable the extglob shell option. – Kusalananda May 17 '22 at 22:00
  • @Kusalananda this question is about grep – con May 17 '22 at 22:01
  • And what's the output of ll chrX_PAR1.phased.vcf.gz | LC_ALL=C sed -n l? – Stéphane Chazelas May 17 '22 at 22:02
  • Also what's the output of type ll? ll is not a standard command, but is often found as an alias for ls -l with possibly other options – Stéphane Chazelas May 17 '22 at 22:03
  • @StéphaneChazelas the file still shows, and type ll shows ll is aliased tols -alF'` – con May 17 '22 at 22:03
  • 2
    The question is what else it shows. For instance, with -F, if the gz file had execute permissions, you'd get a * appended. And sed -n l would show ...gz*$ ($ to show the end of line) – Stéphane Chazelas May 17 '22 at 22:05
  • @thanasisp I only list the file as a test, ll chrX_PAR1.phased.vcf.gz | grep -v 'gz$' still shows the file – con May 17 '22 at 22:05
  • @thanasisp, I already requested a set -n l output which is more portable and more usable than cat -A for that purpose. – Stéphane Chazelas May 17 '22 at 22:10
  • 3
    You may also want to check what ls is aliased to (type ls). If it was aliased to ls --color=always, you'd likely get colour-reset escape sequences after the file name. – Stéphane Chazelas May 17 '22 at 22:13
  • @StéphaneChazelas the coloring is messing up the grep command.

    ls --color=never -l chrX_PAR1.phased.vcf.gz | grep -v gz$ works. If you write this down, I'll accept your answer

    – con May 17 '22 at 22:14
  • 2
    Those escape sequences would have shown in the output of ll chrX_PAR1.phased.vcf.gz | LC_ALL=C sed -n l. Did you try that? – Stéphane Chazelas May 17 '22 at 22:15
  • @StéphaneChazelas yes, ll chrX_PAR1.phased.vcf.gz | LC_ALL=C sed -n l

    gives -rw-r--r-- 1 con domain users 5018 Sep 18 2020 \033[0m\033[01;\ 31mchrX_PAR1.phased.vcf.gz\033[0m$

    – con May 17 '22 at 22:17
  • @con Please [edit] your question and add all requested information to the question. This way it would be easier to show commands and the corresponding output as code blocks, and all relevant information would be in one place, not scattered in question and comments. – Bodo May 17 '22 at 22:46

0 Answers0