Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Rep:
two line averaging
hi guys,
i have output data from one code that needs to get read into another, but the second code can't accept as high of data rate, so i need to average between every two lines. there are seven columns in the file and can be 100 or more rows, but the EOF will be an even number, and the second column can be ignored. it's a constant. here's an output to input example:
the output of the first code would look like
line1 42 a b c d e
line2 42 aa bb cc dd ee
line3 42 aaa bbb ccc ddd eee
line4 42 aaaa bbbb cccc dddd eeee
.
.
.
so with the above example the input file to the next code would look like
the original poster made a good faith effort so even if this is homework i think this guidence wont be cheating (although i have no idea where the variable n above comes from -- i get division by 0 errors when i try to run it as is because it is never defined).
heres my stab at it... (i did first 2 feilds only because i got bored -- season to taste):
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
colucix does the trick
can you explain what the _[i] is doing? i know the "i" is an iterator but the rest of it i haven't seen before
also there are two printf and one print statement, i understand what the last print is doing but what are the printf statments doing in this script, i mean i know what a printf is just not what they are doing in the script
notation is simply the i-th element of the array _ (often I use a single underscore as variable name for brevity).
2. The first printf statement prints out the new line number using a C notation to increment the variable c by one, before it's valued is used
Code:
++c
take in mind that an unitialized variable in awk has value 0.
3. The second printf statement prints out the average of the i-th field, as per your requirement. It is the body of the second for loop, which is executed from the 3rd field to the last one.
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
thanks!
i thought that the _[] was some kind of special character/operator on i
i know that ++ is standard C notation for iterate over (although i'm not sure of the diff between ++i or i++ i'll try to find out), but i hadn't seen the little c before so I didn't know that it is a variable
so are the printf statements, kinds like storing/holding the data in the for loops
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
back again guys,
now i'd like to create averaged lines of data from their nearest neighbors, so like here's an input file
Code:
1 42 0.0 0.4 0.3 0.8 0.7
2 42 0.3 0.1 0.2 0.4 0.1
in the output file the newline of averaged number is line #2, line #1 is the same as the input, and line #3 is line #2 from above, if this thing was run on a 100line file, i think it would give back 198 lines, right?
ok so here i don't know how to create the new in-between line? and how do i "store" the memory of the two nearest neighbors lines so i can average them? when i know how to do those two things, i should hope i could write it???
tabby
Last edited by tabbygirl1990; 10-15-2013 at 11:12 AM.
in the output file the newline of averaged number is line #2, line #1 is the same as the input, and line #3 is line #2 from above, if this thing was run on a 100line file, i think it would give back 198 lines, right?
Code:
1 42 0.0 0.4 0.3 0.8 0.7
an odd index line
2 42 0.3 0.1 0.2 0.4 0.1
an odd index line
3 42 0.0 0.1 0.0 0.2 0.4
an odd index line
4 42 0.7 0.1 0.0 0.0 0.8
an odd index line
5 42 0.3 0.2 0.3 0.8 0.1
so my first thought would be to go through the file once creating the in-between lines, these would all be odd indexed lines, then some way refernce the script only to work on odd indexed lines, right?
Last edited by tabbygirl1990; 10-15-2013 at 11:25 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.