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.
Howcome the quote on top says "between 1 and ymax" and your code says "greater than 0 and <= ymax"? That's not the same (unless the OP's data file contains only integers).
In perl and c the code does
but i do not know about awk anyway
the $ymax and $xmax, are the the upper right coordinates of the square.
$xxx and $yyy, are more legible, and they stand there because the numbers are large, not digits.
As what i want to do, well, is to determine if a given point goes into the left, rigth, top, or bottom boundary, and putting this into a label in the $6th column of the output data
That is right thanks, i was doing copy'n'paste
And thanks for the awk code, i will try it , within the hour
And yes they are integers, large ones, to avoid floating data, but they are scaled by the program which takes this data as input.
Quote:
Originally Posted by Disillusionist
Working from your pseudo code, I have corrected your test statements:
I also don't understand, the OP gave us a broken program to process some data and doesn't even say how that data is formatted.
Ok a stupid question what does OP stands for?
And it is not broken, it is all the program i am using, few lines you might see but they are actually the ones on my script:
[code]
#!/bin/bash
tempo2=$2
touch $tempo2
rm $tempo2
touch $tempo2
clear
sed -e '1,/flag1/d' -e '/flag2/,$d' $1\
| sed '/power/,+3d' \
| tr "\n" " " \
| sed 's/^ *- *//' \
| tr "-" "\n" \
| awk '{print "dat", $1, $17, 10, 20, $11, 0, $12}'\
[\code]
If you run it on the log file to process, you get eight columns of data, as described below
So can we see the data, all be it fake, in the correct format as being given bits and pieces kinda makes it hard to help?
Assuming you are getting the max values then the awk nested ifs should work.
However, looking at the nesting I am not sure it is necessary as I would imagine only one if can be true at a time.
PS. awk has this format too - selector ? if-true-exp : if-false-exp
how do i pass the $ymax, $max, from bash to AWK?
more specific, how do i pass it to this code, instead of 9 and 15?
I tried single quotes but did not work :s
Yes only one condition is expected to be true, you are right, so how about a case statement inside awk?.
Ok, case statement is like red magic for me
About the data mmmmmm thinking how to put it, well in a post below a put a square, it is the same problem, but with more points, and a lot of garbage, i hate log files. That is all, i think, well besides the garbage data which i do not need, the data in the log file is between two flags, somewhere in the text file, and the description of the square is somewhere in the body of the text file also, and between two flags too, thank GOD.
Anyway, the fact is: in perl i used flip-flop operator to cut the data between the flags, as with the first sed command. To be honest, i did my perl script based on these one line commands lol. Just between you and me, only the nested ifs are in perl, the rest are the piped one line commands. I used a shell wrapper, so nobody notices it, yet.
Code:
(8,9)
-------D--------(15,9)
| g |
| g |
| g |
| g |
| g B(15,4)
| g |
(0,2)A g |
| g |
(0,0)-------C--------
(7,0)
g-->garbage
file.data
garbage
garbage
garbage
garbage
flag_square
coordinates ( 0 0 ) ( 15 9 ) ;
glaf_square
garbage
garbage
garbage
garbage
garbage
garbage
flag_data
- data.data + data data_name_des
+ data data
+ data ( 0 2 ) data
+ data name ( %% %% ) ( ## ## ) ;
- data.data + data data_garbage_des
+ data data
+ data ( 10 5 ) data
+ data name ( %% %% ) ( ## ## ) ;
- data.data + data data_name_des
+ data data
+ data ( 8 9 ) data
+ data name ( %% %% ) ( ## ## ) ;
- data.data + data data_garbage_des
+ data data
+ data ( 5 3 ) data
+ data name ( %% %% ) ( ## ## ) ;
glaf_data
garbage
garbage
garbage
garbage
Sorry but the actual data i can not disclose
Quote:
Originally Posted by grail
So can we see the data, all be it fake, in the correct format as being given bits and pieces kinda makes it hard to help?
Assuming you are getting the max values then the awk nested ifs should work.
However, looking at the nesting I am not sure it is necessary as I would imagine only one if can be true at a time.
PS. awk has this format too - selector ? if-true-exp : if-false-exp
So i had a quick look, but based on the current testing criteria (i think i got it right) the value is never set
I can only think that I am either looking at the wrong values or pulled out the wrong values.
Anyway ... some changes should be able to get it to work:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.