ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I write a little script by bash.
-------------------------------------------------------------------------
#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
a=`expr 3 '*' $a`
-------------------------------------------------------------------------
hoge.log is below text.
-- Iterations = 50000
Above srcipt can run in cygwin, Display "150000"
but can't run in Linux, Display "expr: non-numeric argument"
What is different for Linux and cygwin?
I would like tell me how is wrong.
I would like to read a lot of log files like "hoge*.log",
and extract data to calc for one purpose.
I can't use bc in my system.
Would you tell me alternative way?
An alternative to bc is expr. If you answered my question it might help us find out why expr is not working for you -- and then we might be able to make it work.
What is the output if you modify the script to
Code:
#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
echo "a is '$a'"
a=`expr 3 '*' $a`
I ran above code.
One log write by vi and Other dump by other executable program.
write by vi
Display "a is '50000'".
dump by other executable program
Display "' is '50000".
I think last character "'" comes around at head of the line.
Dump use only redirect.
What is different?
I ran above code.
One log write by vi and Other dump by other executable program.
write by vi
Display "a is '50000'".
dump by other executable program
Display "' is '50000".
I think last character "'" comes around at head of the line.
Dump use only redirect.
What is different?
What does "dump by other executable program" mean? Did you copy-and-paste the output from running the script?
Other executable program is benchmark program.
I making this script for assembling result data from benchmark program's dump.
Can we keep it simple to start with and just run the script from the command line and copy-and-paste the output to ensure it is exactly what the script wrote? Once that's known to be working OK we can move onto running it in other ways.
Above srcipt can run in cygwin, Display "150000"
but can't run in Linux, Display "expr: non-numeric argument"
What is different for Linux and cygwin?
Most likely you're trying to read in Linux a log file created in Windows. Different line terminators between the two systems cause troubles to the shell. To avoid the problem, in Linux you can try
Code:
dos2unix hoge.log
before running the script.
A little hint: you can summarize your statements with a single awk line, e.g. with something like:
I write a little script by bash.
-------------------------------------------------------------------------
#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
a=`expr 3 '*' $a`
-------------------------------------------------------------------------
hoge.log is below text.
-- Iterations = 50000
Above srcipt can run in cygwin, Display "150000"
but can't run in Linux, Display "expr: non-numeric argument"
What is different for Linux and cygwin?
I would like tell me how is wrong.
why are you doing an extra pipe to gawk? you can do it with just one gawk statement
An alternative to bc is expr. If you answered my question it might help us find out why expr is not working for you -- and then we might be able to make it work.
What is the output if you modify the script to
Code:
#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
echo "a is '$a'"
a=`expr 3 '*' $a`
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.