Quantcast
Channel: Planet Grep
Viewing all articles
Browse latest Browse all 4959

Mattias Geniar: Awk trick: show lines longer than X characters

$
0
0

The post Awk trick: show lines longer than X characters appeared first on ma.ttias.be.

Here's a quick little awk trick to have in your arsenal: if you want to search through a bunch of files, but only want to show the lines that exceed X amount of characters, you can use awk's built-in length check.

For instance:

$ awk 'length > 350'
$ awk 'length < 50' 

If you combine this with a grep, you can do things like "show me all the lines that match TXT and that exceed 100 characters in length".

$ grep 'TXT' * | awk 'length > 100'

Super useful to quickly skim through a bunch of logs or text-files.

The post Awk trick: show lines longer than X characters appeared first on ma.ttias.be.


Viewing all articles
Browse latest Browse all 4959

Trending Articles