Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created July 29, 2022 18:55
Show Gist options
  • Save codenamev/ff1d72a6f2238d97173d029116fa27be to your computer and use it in GitHub Desktop.
Save codenamev/ff1d72a6f2238d97173d029116fa27be to your computer and use it in GitHub Desktop.
Search files for line
#!/usr/bin/env bash
# usage: file-contains-in-x-lines matchy path/to/file
# Check if single file contains "matchy" in the first 10 lines
head -n 10 $2 | grep -m 1 $1
#!/usr/bin/env bash
# usage: find-files-matching-line matchy .
# Find files that contain "matchy" in the first 10 lines
grep -m 1 -n $1 $2 -H | awk -F'[:]' '{if($2 <= 10) print($1) }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment