Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Matching position and output neighbors within 500 distant Post 302884191 by RudiC on Saturday 18th of January 2014 08:56:20 AM
Old 01-18-2014
Built on miguru's proposal, this (untested) may do what you want:
Code:
awk     'NR == FNR      {arr1[NR] = $1 
                         arr2[NR] = $2  
                         MAX=NR
                         next}

                        {maxval = $2 + 500 
                         minval = $2 - 500
                         for ( i=1; i<=MAX; i++ ) {
                                 if ($1 != arr1[i]) continue
                                 if (minval <= arr2[i] && arr2[i] <= maxval) print
                                }
                        }
        ' $1 $2

If you're sure there's no near duplicates in file 1, you may want to break after print.

Last edited by RudiC; 01-18-2014 at 09:57 AM.. Reason: typo
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

View file on distant machine

Hello everybody, I have a program that connects to a distant machine using a specific port. Then inetd executes a command on that distant machine (M2). What I'd like to do is write a scipt that, given the port, it gives me the command executed. (The script should be launched on the local... (5 Replies)
Discussion started by: Majid
5 Replies

2. Shell Programming and Scripting

Cut output to same byte position

Hi folks I have a file with thousands of lines with fixed length fields: sample (assume x is a blank space) 111333xx444TTTLKOPxxxxxxxxx I need to make a copy of this file but with only some of the field positions, for example I'd like to copy the sample to the follwing: so I'd like to... (13 Replies)
Discussion started by: HealthyGuy
13 Replies

3. Shell Programming and Scripting

Fill the values between -500 to 500 -awk

input -200 2.4 0 2.6 30 2.8 output -500 0 -499 0 -488 0 .......... .......... .... -200 2.4 .... ... 0 2.6 (6 Replies)
Discussion started by: quincyjones
6 Replies

4. Shell Programming and Scripting

loop with OK or NOK output at the same position

Hi This is my script $ cat ./openldap_test.sh #!/bin/bash for ldap_srv in 'testserver1' 'server2' 'server3' 'server4' 'testserver5' 'server6' 'server7' 'server8' 'server9' 'testserver10'; do ldapsearch -LLL -x -H ldap://$ldap_srv '(cn=examplebox)' memberNisNetgroup > /dev/null if ; then... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

5. Shell Programming and Scripting

Find the position of lines matching string

I have a file with the below format, GS*8***** ST*1******** A* B* E* RMR*123455(This is the unique number to locate this row) F* SE*1*** GE** GS*9***** ST*2 H* J* RMR*567889(This is the unique number to locate this row) L* SE* GE***** (16 Replies)
Discussion started by: Muthuraj K
16 Replies

6. UNIX for Dummies Questions & Answers

Help with finding matching position on strings

I have a DNA file like below and I am able to write a short program which finds/not an input motif, but I dont understand how I can include in the code to report which position the motif was found. Example I want to find the first or all "GAT" motifs and want the program to report which position... (12 Replies)
Discussion started by: pawannoel
12 Replies

7. UNIX for Dummies Questions & Answers

Process on distant server

Hello, I have a question regarding how to manage a process on a distant unix server. I perform calculations on a dedicated Unix server (RedHat ELS5.5) using Matlab (installed on the server). The commands are written in a terminal session (via ssh) on my laptop (MacBook Pro6,2 - MacOS X 10.6.7).... (1 Reply)
Discussion started by: antonino_ch
1 Replies

8. Shell Programming and Scripting

Shell script to retrieve first degree neighbors

I have a file with two columns and each pair in the rows denote 2 connected nodes in the network file, edge_list.txt. Given a query file, input.txt, I want to retrieve the nodes that are directly connected (first degree neighbors) to the nodes present in the input.txt. Kindly help. ... (3 Replies)
Discussion started by: Sanchari
3 Replies

9. Shell Programming and Scripting

awk usage for position matching

i have a requirement like this if the line contains from position 294 to 299 is equal to "prabhu" ,then print entire line . i want to use awk awk '{if(substr(294-299) == 'prabhu') print "line" }' filename (1 Reply)
Discussion started by: ptappeta
1 Replies

10. UNIX for Dummies Questions & Answers

String pattern matching and position

I am not an expert with linux, but following various posts on this forum, I have been trying to write a script to match pattern of charters occurring together in a file. My file has approximately 200 million characters (upper and lower case), with about 50 characters per line. I have merged all... (5 Replies)
Discussion started by: biowizz
5 Replies
STRTONUM(3)                                                BSD Library Functions Manual                                                STRTONUM(3)

NAME
strtonum -- reliably convert string value to an integer LIBRARY
Utility functions from BSD systems (libbsd, -lbsd) SYNOPSIS
#include <limits.h> #include <bsd/stdlib.h> long long strtonum(const char *nptr, long long minval, long long maxval, const char **errstr); DESCRIPTION
The strtonum() function converts the string in nptr to a long long value. The strtonum() function was designed to facilitate safe, robust programming and overcome the shortcomings of the atoi(3) and strtol(3) family of interfaces. The string may begin with an arbitrary amount of whitespace (as determined by isspace(3)) followed by a single optional '+' or '-' sign. The remainder of the string is converted to a long long value according to base 10. The value obtained is then checked against the provided minval and maxval bounds. If errstr is non-null, strtonum() stores an error string in *errstr indicating the failure. RETURN VALUES
The strtonum() function returns the result of the conversion, unless the value would exceed the provided bounds or is invalid. On error, 0 is returned, errno is set, and errstr will point to an error message. On success, *errstr will be set to NULL; this fact can be used to dif- ferentiate a successful return of 0 from an error. EXAMPLES
Using strtonum() correctly is meant to be simpler than the alternative functions. int iterations; const char *errstr; iterations = strtonum(optarg, 1, 64, &errstr); if (errstr) errx(1, "number of iterations is %s: %s", errstr, optarg); The above example will guarantee that the value of iterations is between 1 and 64 (inclusive). ERRORS
[ERANGE] The given string was out of range. [EINVAL] The given string did not consist solely of digit characters. [EINVAL] The supplied minval was larger than maxval. If an error occurs, errstr will be set to one of the following strings: too large The result was larger than the provided maximum value. too small The result was smaller than the provided minimum value. invalid The string did not consist solely of digit characters. SEE ALSO
atof(3), atoi(3), atol(3), atoll(3), sscanf(3), strtod(3), strtol(3), strtoul(3) STANDARDS
The strtonum() function is a BSD extension. The existing alternatives, such as atoi(3) and strtol(3), are either impossible or difficult to use safely. HISTORY
The strtonum() function first appeared in OpenBSD 3.6. BSD April 29, 2004 BSD
All times are GMT -4. The time now is 02:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy