Sponsored Content
Full Discussion: Loop and array problem
Top Forums Shell Programming and Scripting Loop and array problem Post 302785089 by hubleo on Sunday 24th of March 2013 05:57:36 PM
Old 03-24-2013
Loop and array problem

Hi, I have the following problem that is beyond what I can currently do with bash scripting.

In file 1, I have ~ 2500000 values. Note this file is not sorted.

Code:
3 19 LABEL_A
3 37 LABEL_B
2 12 LABEL_C
1 15 LABEL_D

I have a list of values in "file 2" ~ 25000 unique lines:
Note - LABEL_7 AND LABEL_8 overlap slightly in their column 2 and 3 values
Code:
1 11 20 LABEL_1
1 18 30 LABEL_2
1 31 40 LABEL_3
2 11 20 LABEL_4
2 21 30 LABEL_5
2 31 40 LABEL_6
3 11 20 LABEL_7
3 15 30 LABEL_8
3 31 40 LABEL_9
4 11 20 LABEL_10

ETC

To run through what I would like to do, as an example:

LABEL_A (FILE 1) has a 3 in column 1, and a value of 19 in column 2.
I want to compare this to every line in FILE 2.

So, if there is a 3 in column 1 of FILE2, and 19 is between the values of columns 2 and 3 of FILE2, see what label this corresponds to in FILE2.

In this example, 19 is between the values in column 2 and 3 (FILE2) for LABEL_7 and LABEL_8.

Desired output: (Note the value of 2 in column 4 below means there are 2 labels that contain the value 19).
Code:
LABEL_A LABEL_7 LABEL_8 2

Full output:

Code:
LABEL_A LABEL_7 LABEL_8 2
LABEL_B LABEL_9 1
LABEL_C LABEL_4 1
LABEL_D LABEL 1 1

I think the code for this will involve while loops and arrays, but I have no idea where to start. Any bash solutions would be great (as this is what I am currently learning), but any assistance at all would be very much appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array Declaration and For Loop

I am just stucked in syntax.This is more like a array and for loop problem. I want to use ls -l command and get filezise and filename of all filenames in the directory in an array (say array#1). After 2 minutes of sleep, i want to get the same information in another array (say array#2). The... (4 Replies)
Discussion started by: 33junaid
4 Replies

2. Shell Programming and Scripting

FTP and run a loop for array problem

Hello, I have a problem with my script whereby it does not want to loop. The function of my script is to FTP into a server and go to each directory/volume in the array 'VOL'. The way the loop is suppose to work, is to go into the first volume, get the files of R(yesterday's date) and... (3 Replies)
Discussion started by: tuffgong2008
3 Replies

3. Shell Programming and Scripting

Help with awk in array in while loop

Hi everyone:) I have 2 files - IN & OUT. Example: IN A:13:30 B:45:40 . . . UNLIMITED OUT Z:12:24 Y:20:15 . . . UNLIMITED I want first row of numbers of IN - OUT. Example 13-12 45-20 My code is (2 Replies)
Discussion started by: vincyoxy
2 Replies

4. Shell Programming and Scripting

Array not surviving while loop

So I'm trying to read datafile into an array, with each line representing one variable in the array. I'm successful at first but somehow it keeps getting erased. i=0 grep '.*' datafile | while read line do echo $i array=$(echo $line) echo ${array} #printing array to make sure it's... (5 Replies)
Discussion started by: DrSammyD
5 Replies

5. Shell Programming and Scripting

Array and Loop Problem

I've got this problem, if I modify an array in the loop and print it, everything is fine as long as I stay in the loop. But, when I print it outside the loop, nothing happens... How can I solve this problem? Here I prepared a sample for you to see my problem; zgrw@Rain:~$ cat test asd 123... (4 Replies)
Discussion started by: zgrw
4 Replies

6. Shell Programming and Scripting

Array with do while and if loop

Hi All, I am trying to run a do while for an array. And in the do while, I'm trying to get a user response. Depending on the the answer, I go ahead and do something or I move on to next element in the array. So far I can read the array, but I can't get the if statement to work. Any suggestions... (5 Replies)
Discussion started by: nitin
5 Replies

7. Shell Programming and Scripting

problem access array outside of loop in bash

Below is a test script I was trying to use so that I could understand why the logic was not working in a larger script. While accessing and printing array data inside the while loop, everything is fine. Outside the loop, i guess everything is null?? The for loop that is meant to cycle... (4 Replies)
Discussion started by: adlmostwanted
4 Replies

8. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

9. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

10. Shell Programming and Scripting

Bash for loop array

Hi there, A bit new to bash and am having an issue with a for loop. I look for filenames in a specified directory and pull the date string from each meeting a certain criteria, and then would like to make a directory for each date found, like this: search 20180101.gz 20180102.gz 20180103.gz... (5 Replies)
Discussion started by: mwheeler12
5 Replies
POE::Loop::Tk(3pm)					User Contributed Perl Documentation					POE::Loop::Tk(3pm)

sub skip_tests {
  return "Tk needs a DISPLAY (set one today, okay?)" unless (
    (defined $ENV{DISPLAY} and length $ENV{DISPLAY}) or $^O eq "MSWin32"
  );
  my $test_name = shift;
  if ($test_name eq "k_signals_rerun" and $^O eq "MSWin32") {
    return "This test crashes Perl when run with Tk on $^O";
  }
  return "Tk tests require the Tk module" if do { eval "use Tk"; $@ };
  my $m = eval { Tk::MainWindow->new() };
  if ($@) {
    my $why = $@;
    $why =~ s/ at .*//;
    return "Tk couldn't be initialized: $why";
  }
  return; }

NAME
POE::Loop::Tk - a bridge that allows POE to be driven by Tk SYNOPSIS
See POE::Loop. DESCRIPTION
POE::Loop::Tk implements the interface documented in POE::Loop. Therefore it has no documentation of its own. Please see POE::Loop for more details. POE::Loop::Tk is one of two versions of the Tk event loop bridge. The other, POE::Loop::TkActiveState accommodates behavior differences in ActiveState's build of Tk. Both versions share common code in POE::Loop::TkCommon. POE::Loop::Tk dynamically selects the appropriate bridge code based on the runtime environment. SEE ALSO
POE, POE::Loop, Tk, POE::Loop::TkCommon, POE::Loop::PerlSignals. AUTHORS &; LICENSING Please see POE for more information about authors, contributors, and POE's licensing. perl v5.10.1 2010-04-11 POE::Loop::Tk(3pm)
All times are GMT -4. The time now is 09:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy