how can I combine these cmds: grep “EQUINO” fallecidossinadef.csv grep “HIDAT”…
- User
how can I combine these cmds:
grep “EQUINO” fallecidos_sinadef.csv | grep “HIDAT” fallecidos_sinadef.csv
I just want to catch anything that has “EQUINO*”OR “HIDAT*”
- Assistant
You can combine the patterns "EQUINO" and "HIDAT" into a single
grepcommand using an extended regular expression with the|(OR) operator. To do so, you need to use the-Eoption withgrepto enable extended regular expressions. Here's how you can do it:grep -E 'EQUINO|HIDAT' fallecidos_sinadef.csvThis command will search for lines in the file
fallecidos_sinadef.csvthat contain either "EQUINO" or "HIDAT". If you want to make sure the patterns "EQUINO" and "HIDAT" are followed by any character (as indicated by the asterisk*in your question), you don't need to include the asterisk in thegreppattern becausegrepnaturally scans for the pattern wherever it appears in the line.However, if you're looking for these strings at the beginning of a word, followed by any characters, you would include the word boundary marker (
\b) to ensure it matches at the start of a word:grep -E '\b(EQUINO|HIDAT)' fallecidos_sinadef.csvIf you're looking specifically for cases where "EQUINO" or "HIDAT" are followed by zero or more characters (the function of the asterisk in some pattern matching), you can explicitly state this using
.*:grep -E '(EQUINO|HIDAT).*' fallecidos_sinadef.csvBut again, this is redundant because
grepwill already match "EQUINO" or "HIDAT" regardless of the characters that follow.