Hi there everyone, as my title stated, how can i shorten my code? Im new to shell scripting and i think my code can be shorten to just a line.
My code is working perfectly and able to generate a report.
I saw people using awk utility and just one line , they are doing the same thing as my long code above.
So i hope someone could help me start up with the awk so i can see if im able to work out with it
Thank you guys!
Hi there everyone, as my title stated, how can i shorten my code? Im new to shell scripting and i think my code can be shorten to just a line.
You don't want to "shorten your code" - you want to shorten the time it needs to get executed. This is sometimes, but not always the same.
First thing you should do in your code is straighten it out:
You should NOT do this: you should not use a "for"-loop for a possibly long list, because the expansion will let the resulting line (after evaluation of the backticks) grow and shell command lines have a certain maximum length (see the "MAX_LIN" kernel constant). Further, you should not use the backticks at all, because they are deprecated. Use a simple pipeline with a while-loop:
Another point is: let. You havent't told us which shell you use, but you do not need "let" any more in any modern bourne-descending shell (ksh, bash, ...). Instead of
simply write
Last hint: you start comparing at the bottom and therefore you have always two tests to perform to find out if a value is within a certain range. Start at the top and you have only one test. Pseudo-code:
A last point: typecast your variables before you use them:
Another way to do the loop, that would not involve the cut statement:
--
Quote:
Originally Posted by bakunin
[..] you should not use a "for"-loop for a possibly long list, because the expansion will let the resulting line (after evaluation of the backticks) grow and shell command lines have a certain maximum length (see the "MAX_LIN" kernel constant).
The for loop is an internal compound shell command that is part of the shell syntax and it does not suffer from these limits..
Quote:
There shall be no limit on the size of any shell command other than that imposed by the underlying system (memory constraints, {ARG_MAX}, and so on).
ARG_MAX is the maximum length of arguments for a new process and that is not the case here.
Even in cases where the shell calls an external program and tries to pass too many elements, then it is not the shell that imposes this limit. It only delivers the error message...
Not sure if that overlap (1999 vs 2999) is mandatory or just a typo.
I'm pretty sure that one calculation is faster than five comparisons, so try sth like
in your loop, and then output e.g. BIN[0], BIN[1]+BIN[2] etc. finally
I have a fasta file as follows
>sp|Q8WWQ8|STAB2_HUMAN Stabilin-2 OS=Homo sapiens OX=9606 GN=STAB2 PE=1 SV=3
MMLQHLVIFCLGLVVQNFCSPAETTGQARRCDRKSLLTIRTECRSCALNLGVKCPDGYTM
ITSGSVGVRDCRYTFEVRTYSLSLPGCRHICRKDYLQPRCCPGRWGPDCIECPGGAGSPC
NGRGSCAEGMEGNGTCSCQEGFGGTACETCADDNLFGPSCSSVCNCVHGVCNSGLDGDGT... (3 Replies)
I have a fasta file as follows
>sp|O15090|FABP4_HUMAN Fatty acid-binding protein, adipocyte OS=Homo sapiens GN=FABP4 PE=1 SV=3
MCDAFVGTWKLVSSENFDDYMKEVGVGFATRKVAGMAKPNMIISVNGDVITIKSESTFKN
TEISFILGQEFDEVTADDRKVKSTITLDGGVLVHVQKWDGKSTTIKRKREDDKLVVECVM
KGVTSTRVYERA
>sp|L18484|AP2A2_RAT AP-2... (3 Replies)
Hi All,
i worte a shell script which will zcat the .gz file and write it in to a tmp file and then again cat the file and convert it to Dos mode. Next step is i am greping the file to search for the particular string on the 1st line and if the string does not exits it will insert the 1st line... (1 Reply)
Hi,
I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory.
finally {
if (null != hibernateSession && hibernateSession.isOpen()) {
//hibernateSession.close();
}
}
It would be great if the script has... (2 Replies)
Hopefully someone here can point me in the correct direction.
I'm working on a username migration and am trying to map my users ols usernames to the new ones.
Right now every user has a username of firstname.lastname i.e. john.doe
I'm trying to create a bash or python script that will take... (3 Replies)
My satellite receiver is equipped with busybox, so a small linux version.
That is why I can not use certain commands like #tomorrow in date commands or #date -d "+1 day"
and thus I have to use: day1=$
I want to download every day 6 files from the internet but the filenames consist of the date... (6 Replies)