You could simplify the echo/read lines at the beginning:-
I agree with bakunin though, why is size important? Clear coding that is flexible if you need to adjust it later is far more important. As an exercise I once wrote a menu system in 60 lines no longer than 80 bytes just so I could print it on a single sheet.
It works just fine and was actually used for a production application, but I can hardly read it back now
Write out your logic, then work out the functions. Finally write your code to match your design and put useful comments in. Make it readable.
Also, make sure you do thorough error checking. Imagine if you issue a cd to a directory that does not exist, and then an rm * You might just destroy your home directory or wherever you were
Size should not be an issue. A neat way does not necessarily mean it will be smaller code, for example, using a loop to read a file and then use a single echo .... | cut .... command to extract the data from the line can be a single line, but using two or three variable substitutions may run far faster even if it does take more lines of code.
Sometimes, bigger is better
Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
I really understand your thought but, here i am given a task of writing this code by reducing the no of lines. The person with least number of lines, will be recognised. Thats the reason i posted this. and i truely accept your piece of thought.
I really understand your thought but, here i am given a task of writing this code by reducing the no of lines. The person with least number of lines, will be recognised. Thats the reason i posted this. and i truely accept your piece of thought.
So, why did you ask for our help. You know that you can easily convert your script into two lines of code by changing some newline characters to semicolon characters. It will be harder to read, harder to maintain, might not be editable with your editor (due to line length), and will be shunned as an example of extremely poor coding practices by anyone who writes code professionally.
But, if that is what you want, go ahead.
The professionals who volunteer their time here to help users learn how to write working code, avoid ridiculous metrics like this like the plague.
You started this thread saying you wanted to improve your code. Making it harder to read and harder to maintain is NOT an improvement!
Sorry for what i posted. I wanted to learn unix in a good way. with good knowledge in it. Right now i am just 2 weeks old in unix trying find a good way of learning and ended up here. Sorry for this post. but i am eager to learn Unix.
Below script is used to search numeric data from around 400 files in a folder. I have 300 such folders. Need help in performance improvement in the script.
Below Script searches 20 such folders ( 300 files in each folder) simultaneously. This increases cpu utilization upto 90% What changes... (3 Replies)
Hi All,
Here is my script
#! /bin/sh
var1=some email id
var2=some email id
grep -i "FAILED FILE FORMAT VALIDATION" /opt >tmp2
diff tmp1 tmp2 | grep ">" >tmp3
if
then
cat tmp3 | mailx -s " Error Monitoring" $var2
else
echo "Pattern NOt Found" | mailx -s " Error Monitoring" $var1... (1 Reply)
can anyone help to share the knowledge on linux os improvement?
1) os account
- use window AD authentication, such as ldap, but how to set /etc/passwd, where to put user home?
2) user account activity
- how to log os user activity
share the idea and what tools can do that...thx (5 Replies)
I write reports daily to a directory that is named with the month and year. I wanted to compress all but the last two months worth of these directories to save space. I am going to cron a job to run on the first of each month to do this clean up. I didn't have zip/unzip on my AIX environment so... (0 Replies)
Hi!
Thank you for the help yesterday
This is the finished product
There is one more thing I would like to do to it but I’m not to certain
On how to proceed I would like to log all output to a log in order to
Be able to roll back
This script is meant to be used in repairing a... (4 Replies)
Hi All,
I have written a script which does some editing in the files, based on user input.This might not be the most elegant way of doing it and there would be many improvements needed.
Please go through it and let me know how it could be improved.
Suggestions are welcome!!
Thanks!... (2 Replies)
Hi All
I am reading a huge file of size 2GB atleast. I am reading each line and cutting certain columns and writing it to another file.
Here is the logic.
int main()
{
string u_line;
string Char_List;
string u_file;
int line_pos;
string temp_form_u_file;
... (10 Replies)