Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.
Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Print every Nth line

Terminal - Print every Nth line
function every() { N=$1; S=1; [ "${N:0:1}" = '-' ] && N="${N:1}" || S=0; sed -n "$S~${N}p"; }
2015-03-21 23:44:59
User: flatcap
Functions: sed
1
Print every Nth line

Sometimes commands give you too much feedback.

Perhaps 1/100th might be enough. If so, every() is for you.

my_verbose_command | every 100

will print every 100th line of output.

Specifically, it will print lines 100, 200, 300, etc

If you use a negative argument it will print the *first* of a block,

my_verbose_command | every -100

It will print lines 1, 101, 201, 301, etc

The function wraps up this useful sed snippet:

... | sed -n '0~100p'

don't print anything by default

sed -n

starting at line 0, then every hundred lines ( ~100 ) print.

'0~100p'

There's also some bash magic to test if the number is negative:

we want character 0, length 1, of variable N.

${N:0:1}

If it *is* negative, strip off the first character ${N:1} is character 1 onwards (second actual character).

Alternatives

There are 3 alternatives - vote for the best!

Terminal - Alternatives
function every() { sed -n -e "${2}q" -e "0~${1}p" ${3:-/dev/stdin}; }
2015-04-03 01:30:36
User: flatcap
Functions: sed
2

Thanks to knoppix5 for the idea :-)

Print selected lines from a file or the output of a command.

Usage:

every NTH MAX [FILE]

Print every NTH line (from the first MAX lines) of FILE.

If FILE is omitted, stdin is used.

The command simply passes the input to a sed script:

sed -n -e "${2}q" -e "0~${1}p" ${3:-/dev/stdin}

print no output

sed -n

quit after this many lines (controlled by the second parameter)

-e "${2}q"

print every NTH line (controlled by the first parameter)

-e "0~${1}p"

take input from $3 (if it exists) otherwise use /dev/stdin

{3:-/dev/stdin}

Know a better way?

If you can do better, submit your command here.

What others think

every() { c=$1;for a in $(seq 1 $c $2);do head -$a $3|tail -1;done } every 20 500 file.txt # prints every 20-th from 1 to 500 lines of file file.txt

However, could not find an easy way to apply this to output of verbose commands.

Maybe eats resources too.

Comment by knoppix5 141 weeks and 3 days ago

@knoppix5

Hmm...

'head' needs fresh input each loop.

The only solution I can think of is to store the input, but that starts getting complicated.

As for the efficiency, I agree it's going to be horrendous.

'head' has to read progressively more and more of the file.

Comment by flatcap 141 weeks and 3 days ago

This is a cleaner way to print every 100 lines:

awk 'NR%100==0' filename.txt
Comment by galaxywatcher 139 weeks and 5 days ago

Cleaner? Perhaps, but that's because it's not as versatile as the original command :-)

It's equivalent to the core:

sed -n '0~10p' FILENAME

To match my command, you need:

every() { N=$1; S=1; [ "${N:0:1}" = '-' ] && N="${N:1}" || S=0; awk "NR%$N==$S"; }

Comment by flatcap 139 weeks and 5 days ago

http://www.tomsshoes.nom.co

http://www.gucci--outlet.us.com

http://www.michaelkorshandbag.us

http://www.curry3.name

http://www.tommyhilfigeroutlet.us.org

http://www.truereligion-jeans.com.co

http://www.adidas-yeezy.us.com

http://www.michaelkorsoutletcanada.com.co

http://www.jordanconcords.net

http://www.coachfactoryoutletmall.us.com

http://www.canadagooseoutlet.nom.co

http://www.thenorthface.net.co

http://www.coach-factoryonline.us.org

http://www.raybanssunglasses.org

http://oakley.sunglassesonline.us.com

http://www.newenglandpatriotsjerseys.us.com

http://www.fitflops.us.org

http://www.gucci.me.uk

http://www.cheap-jordans.us.com

http://www.ralphlaurenpolooutlet.cc

http://www.ugg-canada.ca

http://www.supra-shoes.net

http://www.pandorajewelry.us.org

http://www.coachoutletstoreonline.us

http://www.poloralphlaurenuk.co.uk

http://www.raybansunglasses.me.uk

http://www.dallasmavericksjerseys.com

http://www.mlbjerseys.org

http://www.poloralphlauren.nom.co

http://www.nike-rosherun.in.net

http://www.tomsuk.org.uk

http://www.oakleysunglasses-outlet.com.co

http://www.redbottoms.org.uk

http://www.toms-shoes.cc

http://www.raybanoutlet.net.co

http://www.ralphlaurenoutlet.nom.co

http://www.ray-banwayfarersunglasses.us.com

http://www.adidassuperstar.name

http://www.hollister.in.net

http://www.nikefactoryoutlet.org

http://www.outlets-michaelkors.us.com

http://www.uggoutlet.nom.co

http://timberland.officialfree.net

http://www.airmaxssale.com

http://www.ugg.com.co

http://www.cheaprolexwatches.name

http://www.adidasshoesoutlet.us.com

http://www.oklahomacitythunderjerseys.us.com

http://www.coachoutletofficial.us.com

http://www.replica-watches.us.com

http://www.ralphlaurenoutletsuk.co.uk

http://www.cincinnatibengalsjerseys.us.com

http://www.goldenstatewarriorsjerseys.us.com

http://www.true-religion.me.uk

http://www.christianlouboutin-paris.fr

http://www.adidasoutletstore.net

http://www.niketrainers.uk

http://www.ralphlauren.eu.com

http://www.nhlicejerseys.org

http://www.louis-vuittonoutlet.cc

http://www.ray-banssunglasses.com.co

http://www.michael-kors-handbags.us.org

http://www.ed-hardy.us.org

http://www.rolexwatches.us.com

http://www.montblanc.com.co

http://www.uggoutlet-stores.us.com

http://www.nike-airmax.me.uk

http://www.uggsoutletsale.us.com

http://www.raybanssunglasses.com.co

http://www.raybanwayfarer.com.co

http://www.louisvuitton-outlet.ca

http://www.pandorauk.me.uk

http://www.rosherun.org

http://www.todsoutlet.in.net

http://www.rolexwatchesoutlet.us

http://www.canadagooseukoutlet.me.uk

http://www.hollister-uk.org.uk

http://www.uggclassic.in.net

http://www.canadagoosejacketsoutlet.us.org

http://www.mlbjerseyswholesale.us.com

http://www.uggoutlets.com.co

http://www.outletslouisvuitton.us.com

http://www.cheapjordansshoes.us.com

http://www.louis-vuittonoutlet.us.com

http://www.truereligion.net.co

http://www.jordans.in.net

http://www.outlet-toms.cc

http://www.authenticlouisvuittonhandbags.us.com

http://www.adidastrainers.uk

http://www.christianlouboutinoff.us

http://www.adidasnmd-shoes.us.com

http://www.oakley-sunglasses.net.co

http://www.michaelkors--outlet.us.com

http://www.oakleys.com.co

http://www.nba-jerseys.us.com

http://www.coachoutletstoreonlinesale.us.com

http://www.timberlandoutlet.name

http://www.cheapuggsboots.eu.com

http://www.mcmbags.com.co

http://www.louisvuittonusa.us.com

http://www.wholesalecheapsnapbacks.us.com

http://www.nike-airmaxpascher.fr

http://www.poloralphlauren-outlet.com

http://www.adidasyeezy350.us.com

http://www.tiffanyco.nom.co

http://www.uggboots.nom.co

http://www.coachfactoryoutlet-online.eu.com

http://www.nfljerseyswholesales.us

http://www.ugg-sale.cc

http://www.christianlouboutin.name

http://www.montblancpenofficial.us.com

http://www.pradaoutlet.net.co

http://www.raybansunglassess.com.co

http://www.jordanfemmepascher.fr

http://www.louisvuittonoutletmalls.us.com

http://www.nikeoutlet-online.com

http://www.bostoncelticsjerseys.com

http://www.katespade-outlet.net.co

http://www.newyorkknicksjerseys.us.com

http://www.coachfactoryoutlet-onlinestore.us.com

http://www.michael--korsoutlet.us.com

http://www.abercrombiefitchoutlet.com.co

http://www.raybansonsale.com.co

http://www.hollisterclothing.net

http://www.michaelkorsoutlet-store.us.org

http://timberlandboots.hugeoff.net

http://www.outletuggboots.com.co

http://www.louboutin.us.com

http://www.moncler.me.uk

http://www.raybansunglassesoutlet.net.co

http://www.uggbootaustralia.us.com

http://www.longchamp.us.com

http://www.uggsaustralia.it

http://www.uggoutletstore.com.co

http://www.cheapoakleysunglasses.net.co

http://www.outlet-celine.com

http://www.asicsshoes.name

http://www.adidas.in.net

http://www.louisvuittonlvoutlet.us.com

http://www.clevelandcavaliersjerseys.us.com

http://www.ralphlaurenukofficial.org.uk

http://www.uggs-pascher.fr

http://www.seattleseahawksjerseys.us.com

http://www.pradahandbags.net

http://www.cheapjordansshoes.in.net

http://www.sanantoniospursjerseys.us.com

http://www.hollister-outlet.org

http://www.pittsburghsteelersjerseys.us.com

http://www.mbt.us.com

http://www.ralphlaurenoutletofficial.us.com

http://www.poloralphlaurenukonline.co.uk

http://www.louisvuittonbelt.us.com

http://www.outletmichaelkorshandbags.us.com

http://www.basketballshoes.name

http://www.coachfactoryoutlet-stores.us.org

http://www.vansshoes.name

http://www.louboutinfemme-pascher.fr

http://www.chicagobullsjerseys.com

http://www.cheapuggbootsuk.org.uk

http://www.truereligion-jeans.us

http://www.michaelkorsoultet.us.com

http://www.true-religionjeans.us.org

http://www.cheaptoryburchoutlet.com

http://www.celine-outlet.us

http://www.oakleystore.com.co

http://www.monclerjacketsuk.me.uk

http://www.canadagoosecanada.name

http://www.oakleysunglassess.com.co

http://www.poloralph-lauren.us.org

http://www.ralphlauren-outlet.net.co

http://www.montblanc-pen.name

http://www.uggsbootsoutlet.com.co

http://uggs.uggaustralia.qc.com

http://www.cheaprolexforsale.com

http://www.pandorajewelry.in.net

http://www.nikeoutletstores.us.com

http://www.outletcanadagoose.name

http://www.louboutinshoes.cc

http://www.ugg-italia.it

http://www.oakleysunglassesoutletwholesale.us.com

http://www.raybanpascher.fr

http://www.katespadeoutlets.us.org

http://www.timberlandboots.net.co

http://www.adidasoriginals.in.net

http://www.moncler--paris.fr

http://www.jordanshoes.us.org

http://www.louisvuitton-handbags.com.co

http://www.canadagoosecanada.us.org

http://www.louboutinshoesoutlet.co.uk

http://www.aididasyeezy.org.uk

http://www.rayban-sunglasses.com.co

http://www.louboutinshoessale.com

http://www.ugg-boots.fr

http://www.retrojordans.name

http://www.louisvuittonoutlettrade.us.com

http://www.uggsofficialsite.us.com

http://www.jordan8.net

http://www.beatsbydrdresolo.us

http://www.abercrombieandfitchoutlet.in.net

http://www.cheap-mlb-jerseys.us.com

http://www.hollisteroutletclothing.com

http://www.ugg-bootscheap.com.co

http://www.louis-vuittonoutlet.net.co

http://www.rolexwatchesforsale.name

http://www.washingtonwizardsjerseys.com

http://www.michael-korsbags.us.org

http://www.oakleyssunglasseswholesale.us.com

http://www.michaelkors--outlet.com.co

http://www.burberryoutlet-online.net.co

http://www.kevindurantshoes.name

http://www.cheapnhljersey.us.com

http://www.louisvuittonstores.us.com

http://www.toms.us.org

http://www.giuseppe-zanotti.us.com

http://www.truereligionoutlet.eu

http://www.lebronjames-shoes.net

http://www.mcm.us.org

http://www.gucci-inc.com

http://www.gucci-outlet.org

http://www.jordan4.net

http://www.raybansunglasses.uk

http://www.calvinklein.co.com

http://www.sunglassesoakley.com.co

http://www.cheapuggboots.gr.com

http://www.cheapraybansunglasses.net.co

http://www.katespade.nom.co

http://www.jordan6.net

http://www.moncleroultet.us.com

http://www.tomswedges.us

http://www.jordanretro.name

http://www.louis--vuittonhandbags.us.com

http://www.truereligionsale.com.co

http://www.beatsbydrdre.co.com

http://www.coachfactory-outletonline.eu.com

http://www.oakleysunglasses.gr.com

http://www.christianlouboutinoutlet.com

http://www.coachfactoryoutletclearances.us.com

http://www.ralphlaurenpolo.in.net

http://www.jordanoutlet.us.com

http://www.hilfigeroutlet.in.net

http://www.niketn-pascher.fr

http://www.coachcanadaoutlet.com.co

http://www.omegawatches.us.com

http://www.louis-vuitton.me.uk

http://www.coachoutlet-online-store.com

http://www.uggsbootscheap.us.com

http://www.replicawatches.name

http://www.losangelesclippersjerseys.com

http://www.uggsuk.me.uk

http://www.fitflopsuk.me.uk

http://www.louisvuittonoutletbuy.us.com

http://www.adidas-nmd.co.uk

http://www.jordan13.org

http://www.northface.us.com

http://www.gucci-outlet.cc

http://www.michael-kors--handbags.com

http://www.fitflops.org

http://www.louisvuittonparis.fr

http://www.coachoutletonlinesale.eu.com

http://www.cheapoakleysunglassess.com.co

http://www.coachoutletstoreonlineclearances.us.com

http://www.fitflops.us.com

http://www.jordan3.net

http://www.oakleysunglassescanada.ca

http://www.outletugg.com.co

http://www.chanelhandbags.name

http://www.outletcanadagoose.com.co

http://www.uggbootscanada.ca

http://www.christianlouboutin-pas-cher.fr

http://www.louis-vuitton-borse.it

http://www.lebronjames-shoes.name

http://www.prada.us.org

http://www.cheapnfljerseys-wholesale.us.com

http://www.hogan-scarpe.it

http://www.burberryhandbagsoutlet.in.net

http://www.fitflopssaleclearance.us.org

http://www.oakleyssunglasses.com.co

http://www.nike--rosherun.fr

http://www.cheapuggoutlet.us.com

http://www.coachoutletcheap.us.com

http://www.ugg-australiaboots.us.com

http://www.coachfactoryoutlet-online.us.org

http://www.christianlouboutinsale.me.uk

http://www.uggscheapboots.us.com

http://www.chanelbags.in.net

http://www.miamiheatjerseys.us.com

http://www.longchamp-sac.fr

http://www.redbottoms.me.uk

http://www.kobeshoes.org

http://www.michaelkorsuk.com.co

http://www.hermesbags.us.org

http://www.gooseoutlet.us.com

http://www.outletuggsboots.us.com

http://www.michaelkorstotebags.us.com

http://www.louis-vuittonoutlets.us.org

http://www.louisvuittonofficial.us.com

http://www.michaelkorsoutletsale.us.org

http://www.michaelkorsonlineoutlet.us.org

http://www.monclerjacketsonline.us.com

http://www.coachhandbags.cc

http://www.canadagoosecanada.com.co

http://www.minnesotavikingsjerseys.us.com

http://www.denverbroncosjerseys.us.com

http://www.polooutlet-online.us.com

http://www.edhardyclothing.in.net

http://www.north-faceoutlet.net.co

http://www.monclerpascherhomme.fr

http://www.outletuggs.com.co

http://www.cheapraybans.ca

http://www.airjordan-pascher.fr

http://www.kobebryantshoes.name

http://www.clarisonic.com.co

http://www.ray-ban-sunglasses.com.co

http://www.michaelkorsoutletclearance.us.org

http://www.truereligionjeans-outlet.us.com

http://www.guccishoes.net.co

http://www.toryburchoutlet.us.org

http://www.coachclearance.us.com

http://www.seattleseahawksjersey.us.com

http://www.instyler.in.net

http://www.michaelkorsoutletstores.us.org

http://www.tomsoutlet.org

http://www.abercrombieoutletonline.cc

http://www.canadagoose.com.co

http://www.outletuggs.gr.com

http://www.uggbootsparis.fr

http://www.nikeoutletstore.us.com

2017.1.18xukaimin

Comment by xukaimin 47 weeks and 5 days ago

Your point of view

You must be signed in to comment.