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.
Hi all
I need an awk scipt that uses columns $1 (x) and $3 (y) from a file and print out the regression data to a new file. the following code handles the mathematics
As mentioned in one of your earlier threads: Please post a relevant example of the input file and the expected output you require. Details is what we need/want.
I am not sure I follow ... you say you want regression data and that the code you have presented produces the the data ... what is left for us to answer?
hi
using awk -f gives
-nan -nan
the file looks
1.00 1.61 0.476234
2.00 1.78 0.576613
3.00 1.81 0.593327
i need reg.fil
which has slope and intercept
gav.
hi
PTrenholme
this is perfect but I keep getting a 'file not found' even though I have gawk and permissions ok
Firerat also perfect but how do I change to $1 vs $3
many many thanks
Gav
From your question I assume that you've not been using Linux very long. So here's a "step-by-step" description of how I wrote the script, prepared the data file, and tested the script. (In what follows, everything after the sharp (#), including it, is a comment, not something you need to enter.
All of what follows is assumed to take place in a terminal window. Before you start, go to the post, above, where the script is displayed, highlight the code inside the code block, and copy it to your clipboard. Then open a text editor, paste the code into the editor and save it in some folder. (I used the kate editor, and saved the script in ~/tmp/awk/gav251/gav251.gawk I had, of course, created [mkdir -p ~/tmp/awk/gav251/] that directory before I saved anything there.) Most editors will save files in ~/Documents by default. [kate is a KDE programming editor, but, for this, a simple "Notepad" clone (e.g., leafpad, etc.) would suffice. Do not use a word processor editor. They add "markup" characters that really mess up the script file .)
Oh, in the following, the $ and > are the bash input prompts which should be automatically displayed.
Code:
$ cd ~/tmp/awk/gav251/ # Change your working directory to the folder in which the script was saved.
$ chmod +x gav251.gawk # Make the script executable
$ cat <<EOF >data # You may already have your data file. This is just an example. The name, "data," is arbitrary.
> 1.00 1.61 0.476234
> 2.00 1.78 0.576613
> 3.00 1.81 0.593327
> EOF
$ ./gav251.gawk data # And run the script using the new data file
Note that the file names are quite arbitrary. You're free to use anything you want to use. (Of course, short name are easier to type, and names containing special characters and to by "quoted" when used.)
Oh, to make a change in the script, just open it in the text editor, make the change, and save it. If you use that same name when you save it, you won't need to run the chmod again, but doing so will do no harm.
Hi
it is awk that I am unfamiliar with since I am a biophysicist not programmer, I finnd it is a v. useful UNIX tool. Pls don't concern about general admin (using since 93). When I mentioned 'almost there' it's because the Firerat script works fine it is when I put $3 in line 3 I get
linreg.awk rmsd.tab
0 0
Firstly, it was your script, I just added the shebang ( the #! bit )
Second, [code]your code here[/code] make things much easier to read ( we are 'coders' we care about that )
Third, I copy'n'pasted your code, it worked just fine.. I even switched it to nawk, still fine.
So, the only thing I can think of right now is your input is different
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.