Skip to content

Instantly share code, notes, and snippets.

@henri
Last active September 30, 2024 03:42
Show Gist options
  • Save henri/39a1213717f76a0d892c0051fe77a98e to your computer and use it in GitHub Desktop.
Save henri/39a1213717f76a0d892c0051fe77a98e to your computer and use it in GitHub Desktop.
grep_cheatsheet
# select lines which start with upper case or lower case letter at the start of the line
grep -E "^[a-z]|[A-Z]"
# enable line buffering (useful for dealing with pipes and real time loops)
grep --line-buffered "search term"
# enable highlighting for a match but do not filter output (all of these examples will have a similar effect)
ack --passthru 'hightlight-match-string'
grep "^\|highlight-match-string" --color="always"
grep "^\|highlight-match-string" --color
grep "^\|highlight-match-string"
grep "\|highlight-match-string"
# use sponge to soak up a file and then write back to the same file (grep goodnes)
cat remove_lines_from_me.txt | grep -vx --fixed-strings --file=delete_pattern_file_one_per_line.pattern | sponge remove_lins_from_me.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment