Awk trick: show lines longer than X characters

Datetime:2016-08-23 00:56:24         Topic: AWK          Share        Original >>
Here to See The Original Article!!!

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.

Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek,public speaker and podcaster . If you're interested in keeping up with me, have a look at my podcast and weekly newsletter below. For more updates, follow me on Twitter as @mattiasgeniar .

SysCast podcast

In the SysCast podcast I talk about Linux & open source projects, interview sysadmins or developers and discuss web-related technologies. A show by and for geeks!

cron.weekly newsletter

A weekly newsletter - delivered every Sunday - for Linux sysadmins and open source users. It helps keeps you informed about open source projects, Linux guides & tutorials and the latest news.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!


Put your ads here, just $200 per month.