Programming and Scripting :: Beta testers needed



Quote (^thehatsrule^ @ Jan. 29 2008,14:29)
Quote
I would also like to replace sed with awk if it can perform search & replace easily, like sed.
I'd stick with sed because it should be a 'lighter' binary (unless you have some reason to worry about having a missing sed)

Also, if you can, avoid using search and replace at all if possible.    For example, looking at your code in your first post, you can make a function that can print the output from variables instead of replacing the text in OUTPUT_FORMAT.

Yes. Just because of that. I've read that awk is more common than sed.
From Wikipedia:
Quote
A version of the AWK language is a standard feature of nearly every modern Unix-like operating system available today.
Quote
Besides the Bourne shell, AWK is the only other scripting language available in a standard Unix environment.

But now when you said that sed is lighter, I'll plan my script primary to look for sed, and then awk. =)

About for+case:
I think I have to stick with multiple cases. If I pass OUTPUT_FORMAT for for -loop to go trough and
then if/when sed/awk modifies it (still insife for -loop), for -loop won't know it's been modified. Right?
Then case inside for -loop might have to modify same information, bit in different place (in OUTPUT_FORMAT), more than once. Ok. Cituation like this is rare.Possible only is user has specified same spot (-UPTIME- for example) more than once.
With many case -sentences OUTPUT_FORMAT is modified instantly if any of the case -sentences is triggered.

Anyway tests that I performed showed very little difference, so I think this "performance tweaking" with for-case vs. many cases isn't really relevant anymore. I'd like to focus more to make this script to work on as many platforms/OSes as possible, meaning to make this use most common UNIX tools awailable.. ;) Many thanks anyway.

And I will need the search and replace because user running this script can specify his/her own output from the command line ie: ./sysinfo.sh "Uptime: -UPTIME- | Free RAM: -MEMFREE-"
Basically sed (maybe awk also) is there to search & replace user defined command line arguments.

Get it? ;)

Ok. Enough long post already. Brb going to moon.

Quote
And I will need the search and replace because user running this script can specify his/her own output from the command line ie: ./sysinfo.sh "Uptime: -UPTIME- | Free RAM: -MEMFREE-"
Basically sed (maybe awk also) is there to search & replace user defined command line arguments.
How often are you going to use those custom lines?  If you really want to be somewhat more efficient you could only use sed/awk when you have custom lines instead (or somehow specify and eval given variables on the command line?).  It really depends on how much you want to spend on this.

That's true. It would be more efficient that way. It may be a bit complex to implement, but I'll try it some time. =)
New relase

Some if+grep statements still need to change.
And as usual, comments and suggestions are very welcome. ;)

Go to first post to get it

Bug spotted.
It does not result to any error. But as I ran that script with bash -x I could see how it uses cat to get information from /proc even if specific information is already there. It makes this script slower. Even I have code to check if script already has the information needed, it still goes to fetch the information again.
Here's an example code where it fails to regonize that the data is already there:
Code Sample
   function parsememinfo {
       
       # Get memory information if there isn't already
       if [ -z "$MEMINFO" ]
       then
           MEMINFO=`cat /proc/meminfo`
       fi
       PARSED=${MEMINFO#*$*:}
       PARSED=${PARSED%% kB*}
       echo $PARSED
   }


Any of you have any solution to this?
First the code was like this: test -z $VARIABLE && VARIABLE="data"
and it didn't worked any better than the code above.

Next Page...
original here.