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 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.