Unable to grab output in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to grab output in variable
# 8  
Old 09-27-2016
Quote:
Originally Posted by wisecracker
I caught it before seeing your post and the error will still exist above 59.999 secs.
Even the minutes could be taken into account if required.
That is the OPs job...
Actually, it's not necessary to evaluate the minutes, only to see whether they are zero. If I would do it in the shell, I would therefore not do fixed substrings to extract the miliseconds, but something like - assuming that the line containing the desired value is in variable rtime -
Code:
${rtime#*m}

and then use substrings to get rid of the period (or use zsh instead of bash, where you can work with decimal numbers).
Code:
${rtime%m*}

would extract the part to the left of the 'm', but I would deal with the minutes using the regular expression feature of the shell.

This means, you have to do four steps with the output: Getting the line containing the real number (you used an array, but I would feel safer doing it by grep), testing that the minutes are 0, extracting the part for the miliseconds, and removing the dot so that you can do integer arithmetic. Of course it is a matter of taste, but this is the point where I tend to switch to a more flexible programming language.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to redirect output to a file

I m not able to redirect the java version to a file however, it shows as output when I run my script. bash-3.2$ more 1test.tmp java_version=`which java` echo "MY JAVA:"$java_version version=`"$java_version" -version` echo $version >>/tmp/moht/java_version.log $java_version -version 2... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. UNIX for Beginners Questions & Answers

How do I use grep to grab prime number output from my factor program?

I have a factor program that runs and outputs to stdout all the prime numbers that are specified in the given paramters, in this case 30000000-31000000. Command: factor/factor 30000000-31000000 Sample output: 30999979 = 30999979 30999980 = 2^2 5 11 140909 30999981 = 3 10333327... (6 Replies)
Discussion started by: steezuschrist96
6 Replies

3. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

4. Shell Programming and Scripting

Unable to obtain the desired output

Hi, I am unable to get beyond the exit function. The shell script is used to look for masked files and copy paste them to another location. Please refer to the code below for more information. Thanks Brinjit #!/usr/bin/ksh... (10 Replies)
Discussion started by: brinjit
10 Replies

5. Shell Programming and Scripting

Unable to assign command output to variable

Code set -x STATUS="0" echo $STATUS for i in `ls -ltr Report*|awk '{ print $9 }'` do if then flg = "`head -1 "$i" |cut -c 31-33`" echo `head -1 "$i" |cut -c 31-33` echo $flg if then echo "having Fun" STATUS="2" else echo "no Fun" fi fi (2 Replies)
Discussion started by: Funkeydude
2 Replies

6. Shell Programming and Scripting

Unable to get the Value of variable

Hi, I have a properties file that is read by the Unix Shell Script. The script prompt the user to enter some input feilds and then based on user input it needs to look other values from properties file Example abc.properties file has following properties Dev.DB2.name=someDEVDB2... (3 Replies)
Discussion started by: WhtNxt01
3 Replies

7. UNIX for Dummies Questions & Answers

Unable to understand ps output.

I m executing ps command and sorting it according to memory usage. Please find the output of the command. # ps aux --sort pmem USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 2060 624 ? Ss 01:54 0:00 init root 2 0.0... (1 Reply)
Discussion started by: pinga123
1 Replies

8. UNIX for Dummies Questions & Answers

Grab Portion of Output Text (sed, grep, awk?)

Alright, here's the deal. I'm running the following ruby script (output follows): >> /Users/name/bin/acweather.rb -z 54321 -o /Users/name/bin -c Clouds AND Sun 57/33 - Mostly sunny and cool I want to just grab the "57/33" portion, but that's it. I don't want any other portion of the line. I... (5 Replies)
Discussion started by: compulsiveguile
5 Replies

9. Shell Programming and Scripting

unable to redirect output

I have a script on Linux that is using sfdisk to partition a usb drive. I'm trying to redirectory the standard out and standard error which works, however, there is still messages being diplayed. I guess it's kernel messages? Is there a way to redirect this output? Thanks (5 Replies)
Discussion started by: lochraven
5 Replies

10. UNIX for Dummies Questions & Answers

unable to view the output through this cgi

#!/bin/env perl read(STDIN,$temp,$ENV{'CONTENT_LENGTH'}); @pairs=split(/&/,$temp); $DISPLAY1 = "/u/inarram111/dev/web/HNW/BNY/unsecure-html/myscript2.html"; $DATAFILE1 = "/u/inarram111/dev/web/HNW/BNY/unsecure-cgi-bin/datafile"; open (DATAFILE1, ">$DATAFILE1") || die " Error opening log file... (0 Replies)
Discussion started by: rishchand
0 Replies
Login or Register to Ask a Question