Search code examples
shellgreppattern-matchingzgrep

How to zgrep an UPPERCASE as a lowercase without pipes / variables / echo


How to zgrep an UPPERCASE PATTERN as it was a lowercase, e.x.:

zgrep 'MYPATTERN' *.gz

matching: mypattern

Without: pipes, echoes, files or variables. E.x.:

s="Hello World!" 
echo $s  # Hello World!
a=${s,,}
zgrep "$a" *.gz

NOR

echo 'MYPATTERN' | sed -e 's/.*/\L&/g'  #this line not tested

NOR

zgrep -i 'MYPATTERN' *.gz #option -i is to heavy

The goal is to search for a plain simple hexa string in log files, but they are always given as UPPERCASE, but logged as lowercase.

The harvesting is made in a shared remove server where writing a function wouldn't be the nicest. I'm searching for a clean solution. That's the reason why I'm avoiding pipes and variables.

subcommands are welcome "``" but without pipes or many commands inside it.


Solution

  • That's a crazy set of restrictions. How about

    zgrep "$(tr '[:upper:]' '[:lower:]' <<<"MYPATTERN")" *.gz
    

    How is zgrep -i "too heavy"?