Thursday | 21 NOV 2024
[ previous ]
[ next ]

Grep Shortcut

Title:
Date: 2022-01-02
Tags:  

A grep snippet so I can do search {directory} {keywords}. Extremely useful as I rarely remember how grep works even though I use it quite a bit.

#!/usr/bin/bash

grep --color=always \
    --exclude="*.min.*" \
    --exclude="*nohup*" \
    --exclude="*tsconfig*" \
    --exclude="package.json" \
    --exclude="package-lock.json" \
    --exclude=".*" \
    --exclude-dir=.git \
    --exclude-dir=node_modules \
    --exclude-dir=logs \
    --exclude-dir=target \
    -RIinT \
    "$2" \
    "./$1" | awk '{$1=$1};1'

Exclude various files and directories.

R - Recursively search directoriesI - Ignore binary filesi - Ignore casesn - Show the line numberT - Align the results on tabs so that results aren't indented

Awk is doing some formatting. Not sure what but something.