r/UnixProTips • • Feb 22 '15
grep . /files/you/want/*
Simple but effective way to cat a bunch of files with the filename: before each line.
Handy if you want to have a look at a few smaller files at once. Also, it squeezes out empty lines.
9
Upvotes
12
u/cpitchford Feb 22 '15
If you use ^ you're matching start of line If you use . you matching any character... which will exclude blank lines
That's always handy for sticking line numbers at the start of each line too
tl;dr use ^ not . to match every line
1
u/joedonut Feb 22 '15
Why|how does it suppress blank lines? I'd always used:
to skip blank lines and comments.
1
u/Paradiesstaub May 20 '15
Instead of grep I use the faster/more focused ack-grep utility.
ack-grep --context=3 --ignore-case [regex]Man ack-grep:
Ack is designed as an alternative to grep for programmers.
Ack searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, ack prints the matching lines. PATTERN is a Perl regular expression. Perl regular expressions are commonly found in other programming languages...