To talk about efficiency in the shell.

Source: Internet
Author: User

There's nothing going on today. A lot of operations in the shell about efficiency issues
No, nothing else, no use.
It's just something to do.
At first, that's the arithmetic.
What I recommend here is to use the $ (()) method for simple operations.
Because calculators like expr or BC certainly don't have Linux built-in fast
Summed up is a sentence
That is, you can use the built-in variables and don't use external commands.
And then there's the problem of variable interception.
For example, a general variable can be done with sed.
But the SED is telling the truth efficiency is really not very high, sometimes waiting for a file output
It'll be a long time.
Can be intercepted with some of the built-in variables in ${}
Of course, if it's a dozens of-file thing, it's not that hard.
Random, which use which.
But when you deal with thousands of good tens of thousands of data, that's not the time.
You don't have to be totally full.
You know, when you need it, you can find it.
such as Baidu what keyword can find the corresponding solution
There are things that can be done with tools, do not have to write a script to deal with
After all, the tools have been baptized for so many years.
The bad tools must be eliminated.
And it's really important to nest loops, I just want to say
Unless the data is very small
Or you can wait.
Process data to handle data
Just doing one thing at a time.
For example, someone asked a question today.
is to have a 200G text file
Want to print out about 2000 lines of content
Line number of line 2000 in a text file
His solution is to loop the line number file with a for, and then use SED to fetch
I just made a simple estimate, this JB is not nonsense?
For loop, loop over 2000 times, then SED is to traverse that 200G file
I gave a solution, but it's complicated, and then I'm going to say my way.
For reference only, there must be a better solution than mine

The first is that SED cannot be filtered by branch because the 2000 rows are discontinuous, sed I can't
Maybe the sed big God said can be done, I can't, I give a general solution
I'm using Awk,awk, and that's the key usage.
awk '/{if (nr==line) print}/' file
is to use NR to determine the line number, then only need to traverse through the file can be
The important thing is to get the nr==line problem fixed.
Because awk supports (nr==23| | NR==25)
Like this, it can be a lot of choice
Then the line number file with TR and sed after processing can be complete () in the middle of the type of a line of text
Just copy the past to awk.
I've done an experiment, I'm sure I've got it done.
But the code is in the history after the shutdown.
I'm too lazy to turn over.

Just summed up so much, not much to say, ready to wash and sleep

This article comes from the "Dashazi's blog" blog, please be sure to keep this source http://dashazi.blog.51cto.com/10354524/1754976

To talk about efficiency in the shell.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.