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.
I have been playing with this for hours. I have two values I set min and max. When I use echo on them seperately they print the values fine. When I concat the values in echo the first value does not print. When I set the values outside of awk using the terminal interactivly it prints fine. When I tried
...
#FIND MIN VALUE
min=`awk 'BEGIN{FS=","}; min=="" || $3 < min {min=$3} END {print min}' nonhead`
#FIND MAX VALUE
max=`awk 'BEGIN{FS=","}; max=="" || $3 > max {max=$3} END {print max}' nonhead`
echo $max
echo $min
echo $max + $min
...
Here is the file I am using awk on. Not sure if that helps
Of course it helps!
Anyhow, the following (still) works:
Code:
#!/bin/bash
#FIND MIN VALUE
min=`awk 'BEGIN{FS=","}; min=="" || $3 < min {min=$3} END {print min}' nonhead`
#FIND MAX VALUE
max=`awk 'BEGIN{FS=","}; max=="" || $3 > max {max=$3} END {print max}' nonhead`
echo -n $max + $min ]
echo ""
I copied/pasted the data you provided into a file called "nonhead".
#!/bin/bash
#FIND MIN VALUE
min=`awk 'BEGIN{FS=","}; min=="" || $3 < min {min=$3} END {print min}' nonhead`
#FIND MAX VALUE
max=`awk 'BEGIN{FS=","}; max=="" || $3 > max {max=$3} END {print max}' nonhead`
echo -n $max + $min ]
echo ""
I copied/pasted the data you provided into a file called "nonhead".
Thanks for the help with this whats with the ] in
Code:
echo -n $max + $min ]
Maybe its the version of bash I am using. Currently at 4.1.5(1)-release (i486-pc-linux-g
Just to add onto Guttorm's previous statement, you can indeed use awk to remove the \r if you are constantly dealing with Windows files.
Take a look at the RS component of awk, is default is a newline (\n) but it can be set to multiple values, such as:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.