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.

Universal configuration monitoring and system of record for IT.
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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Extract specific lines from a text file using Stream Editor (sed)

Terminal - Extract specific lines from a text file using Stream Editor (sed)
head -n1 sample.txt | tail -n1
2011-06-14 17:45:04
User: gtcom
Functions: head tail
0
Extract specific lines from a text file using Stream Editor (sed)

You can actually do the same thing with a combination of head and tail. For example, in a file of four lines, if you just want the middle two lines:

head -n3 sample.txt | tail -n2

Line 1 --\

Line 2 } These three lines are selected by head -n3,

Line 3 --/ this feeds the following filtered list to tail:

Line 4

Line 1

Line 2 \___ These two lines are filtered by tail -n2,

Line 3 / This results in:

Line 2

Line 3

being printed to screen (or wherever you redirect it).

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
sed -n -e 1186,1210p A-small-practice.in
2011-06-04 10:53:46
User: evandrix
Functions: sed
Tags: sed
0

Using sed to extract lines in a text file

If you write bash scripts a lot, you are bound to run into a situation where you want to extract some lines from a file. Yesterday, I needed to extract the first line of a file, say named somefile.txt.

cat somefile.txt

Line 1

Line 2

Line 3

Line 4

This specific task can be easily done with this:

head -1 somefile.txt

Line 1

For a more complicated task, like extract the second to third lines of a file. head is inadequate.

So, let's try extracting lines using sed: the stream editor.

My first attempt uses the p sed command (for print):

sed 1p somefile.txt

Line 1

Line 1

Line 2

Line 3

Line 4

Note that it prints the whole file, with the first line printed twice. Why? The default output behavior is to print every line of the input file stream.

The explicit 1p command just tells it to print the first line .... again.

To fix it, you need to suppress the default output (using -n), making explicit prints the only way to print to default output.

sed -n 1p somefile.txt

Line 1

Alternatively, you can tell sed to delete all but the first line.

sed '1!d' somefile.txt

Line 1

'1!d' means if a line is not(!) the first line, delete.

Note that the single quotes are necessary. Otherwise, the !d will bring back the last command you executed that starts with the letter d.

To extract a range of lines, say lines 2 to 4, you can execute either of the following:

sed -n 2,4p somefile.txt sed '2,4!d' somefile.txt

Note that the comma specifies a range (from the line before the comma to the line after).

What if the lines you want to extract are not in sequence, say lines 1 to 2, and line 4?

sed -n -e 1,2p -e 4p somefile.txt

Line 1

Line 2

Line 4

Know a better way?

If you can do better, submit your command here.

What others think

Nappy bags are first and foremost created to maintain a new method of getting cleanse nappies for ones newborn as well as child. Having a newborn together on the long or short make your way must not be a major creation in case you maintain your bag crammed constantly with all the essential items. Those items that are required can vary good age http://www.hermesbeltsbirkinkellybag.co.uk/ and requires with the youngster. Ease and comfort and treatment whilst overseas are created less difficult using a bag to cart the products.The main objective of any bag is to take baby diapers. Infants could go via a large amount of nappies is simply a little while. You'll also must have a very container associated with pre-moistened baby baby wipes to help keep the skin thoroughly clean. A number of moms and dads convey a container regarding whole milk or formula into the bag, however can make temperature management problems. Mother and father might bring assessed method combined so that a compounding can be rapidly prepared in the event the baby is able to be fed. An alteration of clothes in addition to containers associated with child food are other common things to invest the actual your bag.Look regarding appears which can be reinforces strong parts intended for band or perhaps deals with. You don't need your bag to sink less than utilize. A good quality bag might last from the many weeks connected with baby diaper carrying and grow look great.You can find bags that are various sizes. The scale will most likely be determined by the volume of devices that you need to take with you on your own travel. As little ones obtain bigger, those things how they need to have usually are bigger as well. The particular bag will most likely should grow using your child.The bag needs to be easily cleaned. Spilled food items, dirt and dust usually are not positive things to own on the bag close to your infant products. Whether or not the cover is actually natural leather as well as man-made leather and can be easily wiped lower using a humid towel as well as other supplies, you need to be capable to cleanse the surface efficiently.The addresses or even hauling band of the take bag needs to be safely fastened. Even tho it's a modest tragedy if the band drags loose and spots this contents of this bag onto the surface. Picking out larger shoulder straps could be more comfortable to wear once the bag is more heavy than usual. Narrow connectors may well often cut into ones make.You may wish to see whether you aren't you would like spaces from the nappy bags you end up picking. Some bags are usually wide ope, other people are constructed with purses and pockets. There might be bottle of wine holders within the outside surface of the bags so they never outflow on to clean up nappies or maybe garments. It is best to choose a bag which has a closure product such as a zip.

Comment by stephanieg915 1 week ago

Whilst in the strategy of determining which often promotional items you will be offering, you may ponder whether you must go the regular path. By simply tradition, which means could even get discarded charm the concept people would like to get the normal promotional items, including writing instruments and also bags. This can be something that often leads one to the predicament specifically because these products are less costly as opposed to higher and more appealing electronic gadgets for instance Hardware recollection twigs. On the other hand, you will be astonished to be aware of of which pens in addition to bags even now maintain the interest individuals.Promotional writing instruments are certainly stuff that come in the market industry some time already. The truth is, it's commonly considered that if the reasoning behind offering products pertaining to campaign was developed, companies presently received markers inside their brains as the greatest options. This may be caused by the belief that this kind of items are inexpensive and should not end up being hefty within the finances of those who are intending to disperse most of these for free. Apart from this particular, writing instruments are quite valuable. These are used to produce just about everything, which explains why folks would not think twice to take these kind of.Promotional bags seemed to be very well liked options. For the people businesses that are incredibly a lot considering ensuring his or her models have emerged by means of more people rather than just those that acquired the corporate products, bags are indeed the very best selections. Whenever bags are usually carried about, business companies along with art logos usually are thus viewable and seen through more people. For that reason, your promoting component is definitely further improved, with a lot more customers becoming gotten to by the subliminal audio message of the brand brand name and identify. This is actually the main reason the reason why there are far more companies that still utilize these for offers as opposed to trying the revolutionary. It is rather crystal clear of which giving away advertising pens along with bags features a great advantage. Even though this can look like less exciting in comparison to other products that are definitely more technologically innovative, folks would never restrain their selves coming from actually obtaining these when these are in fact given at no cost. As these be cheaper, no doubt it is smart to however start using thise since your fishing lures; things which really would cause you to spend less on your finances and still supply you with the best results. As a result, your small business really would maximum benefit from the.With the benefits receiving by simply promo bags, there is certainly really zero satisfied answer why it is best to avoid it an option. Even so, while this stuff are usually cheap in addition to common, you shouldn't neglect the intense want that these have high-quality. Which means that it is best http://www.hermesbeltsbirkinkellybag.co.uk/ to uncover whether or not people that you're giving out are true best in the industry. Even though they're affordable isn't going to resulted in there would always be you should not make sure top quality. Individuals would never established this particular factor besides even if these products are free of charge.

Comment by stephanieg915 1 week ago

http://www.canadagoosefemmehomme2016.fr/canada-goose-whistler_318.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-freestyle_324.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-boutique-paris_167.html

http://www.canadagoosefemmehomme2016.fr/chapeau-canada-goose_238.html

http://www.canadagoosefemmehomme2016.fr/nouvelle-collection-canada-goose_451.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-authentique_434.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-site-fiable_136.html

http://www.canadagoosefemmehomme2016.fr/ou-acheter-canada-goose_100.html

http://www.canadagoosefemmehomme2016.fr/veste-style-canada-goose_223.html

http://www.canadagoosefemmehomme2016.fr/veste-canada-goose-femmes_189.html

http://www.canadagoosefemmehomme2016.fr/destockage-canada-goose_286.html

http://www.canadagoosefemmehomme2016.fr/expedition-parka-canada-goose_210.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-taille-xs_224.html

http://www.canadagoosefemmehomme2016.fr/constable-parka-canada-goose_97.html

http://www.canadagoosefemmehomme2016.fr/parka-montebello-canada-goose_379.html

http://www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-homme_328.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-fourrure-coyote_244.html

http://www.canadagoosefemmehomme2016.fr/shelburne-canada-goose_418.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-calgary_278.html

http://www.canadagoosefemmehomme2016.fr/promo-canada-goose_263.html

Comment by sguerra376 4 days ago

http://www.canadagoosefemmehomme2016.fr/ou-acheter-une-canada-goose_313.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-the-chateau_364.html

http://www.canadagoosefemmehomme2016.fr/bomber-canada-goose_240.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-ca_288.html

http://www.canadagoosefemmehomme2016.fr/chateau-parka-canada-goose_225.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-sans-manche_325.html

http://www.canadagoosefemmehomme2016.fr/vente-canada-goose_194.html

http://www.canadagoosefemmehomme2016.fr/macmillan-canada-goose_270.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-chilliwak_109.html

http://www.canadagoosefemmehomme2016.fr/mystique-canada-goose_343.html

http://www.canadagoosefemmehomme2016.fr/la-canadienne-canada-goose_294.html

http://www.canadagoosefemmehomme2016.fr/parka-homme-canada-goose_84.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-moncler_415.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-montebello-parka_81.html

http://www.canadagoosefemmehomme2016.fr/doudoune-sans-manche-canada-goose_314.html

http://www.canadagoosefemmehomme2016.fr/fourrure-canada-goose_70.html

http://www.canadagoosefemmehomme2016.fr/vente-canada-goose-montreal_160.html

http://www.canadagoosefemmehomme2016.fr/prix-canada-goose-new-york_215.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-rennes_423.html

http://www.canadagoosefemmehomme2016.fr/homme-canada-goose_350.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-summit_236.html

http://www.canadagoosefemmehomme2016.fr/resolute-canada-goose_116.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-snow-mantra_209.html

http://www.canadagoosefemmehomme2016.fr/canada-gooser_220.html

http://www.canadagoosefemmehomme2016.fr/mystique-parka-canada-goose_229.html

http://www.canadagoosefemmehomme2016.fr/citadel-parka-canada-goose_62.html

Comment by sguerra376 4 days ago

http://www.canadagoosefemmehomme2016.fr/canada-goose-couleur_471.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-pbi-chilliwack-bomber_73.html

http://www.canadagoosefemmehomme2016.fr/parka-chateau-canada-goose_94.html

http://www.canadagoosefemmehomme2016.fr/manteau-canada-goose-a-vendre_450.html

http://www.canadagoosefemmehomme2016.fr/veste-canada-goose-homme_474.html

http://www.canadagoosefemmehomme2016.fr/branta-canada-goose_271.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-occasion_413.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-pas-cher-france_142.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-taille-s_327.html

http://www.canadagoosefemmehomme2016.fr/blouson-canada-goose_156.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-ou-parajumpers_414.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-victoria-parka_462.html

http://www.canadagoosefemmehomme2016.fr/parka-trillium-canada-goose_333.html

http://www.canadagoosefemmehomme2016.fr/revendeur-canada-goose-paris_266.html

http://www.canadagoosefemmehomme2016.fr/bomber-canada-goose_240.html

http://www.canadagoosefemmehomme2016.fr/goose-canada-pas-cher_140.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-chateau-parka_247.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-mystique-femme_179.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-entrepot_141.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-new-york-prix_159.html

http://www.canadagoosefemmehomme2016.fr/fr-canada-goose_182.html

http://www.canadagoosefemmehomme2016.fr/manteau-canada-goose_433.html

http://www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-france_265.html

http://www.canadagoosefemmehomme2016.fr/parka-canada-goose-homme-pas-cher_419.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-kensington-parka-femme_448.html

http://www.canadagoosefemmehomme2016.fr/skreslet-parka-canada-goose_469.html

Comment by sguerra376 2 days ago

www.canadagoosefemmehomme2016.fr/canada-goose-chateau-noir_174.html

www.canadagoosefemmehomme2016.fr/ou-acheter-une-doudoune-canada-goose_348.html

www.canadagoosefemmehomme2016.fr/canada-goose-mystique-femme_179.html

www.canadagoosefemmehomme2016.fr/canada-goose-parka-langford_176.html

www.canadagoosefemmehomme2016.fr/blouson-aviateur-canada-goose_299.html

www.canadagoosefemmehomme2016.fr/prix-canada-goose-femme_206.html

www.canadagoosefemmehomme2016.fr/canada-goose-femme-courte_322.html

www.canadagoosefemmehomme2016.fr/parka-canada-goose-soldes_241.html

www.canadagoosefemmehomme2016.fr/canada-goose-achat_221.html

www.canadagoosefemmehomme2016.fr/nouvelle-canada-goose_193.html

www.canadagoosefemmehomme2016.fr/prix-doudoune-canada-goose_428.html

www.canadagoosefemmehomme2016.fr/foxe-bomber-canada-goose_392.html

www.canadagoosefemmehomme2016.fr/canada-goose-parka-banff-homme_403.html

www.canadagoosefemmehomme2016.fr/revendeur-canada-goose-paris_266.html

www.canadagoosefemmehomme2016.fr/canada-goose-laval_347.html

www.canadagoosefemmehomme2016.fr/canada-canada-goose_246.html

www.canadagoosefemmehomme2016.fr/entrepot-canada-goose_158.html

www.canadagoosefemmehomme2016.fr/canada-goose-yorkville-bomber_408.html

www.canadagoosefemmehomme2016.fr/canada-goose-montebello-prix_254.html

www.canadagoosefemmehomme2016.fr/manteau-canada-goose-prix_332.html

www.canadagoosefemmehomme2016.fr/canada-goose-sherbrooke_245.html

www.canadagoosefemmehomme2016.fr/canada-goose-authentique_434.html

www.canadagoosefemmehomme2016.fr/boutique-canada-goose_378.html

www.canadagoosefemmehomme2016.fr/boutique-canada-goose-paris_302.html

www.canadagoosefemmehomme2016.fr/canada-goose-homme-parka_111.html

Comment by sguerra376 1 day ago

Your point of view

You must be signed in to comment.