Sponsored Content
Full Discussion: simple array problem
Top Forums Shell Programming and Scripting simple array problem Post 302467451 by enes71 on Friday 29th of October 2010 11:38:18 AM
Old 10-29-2010
a slight change and comparison of each array value

Hello again experts;

I have been working on my code to make it multitask. I deleted unnecessary fields in my input file, here is the last version;

Code:
1716978 7451870 -60 00:3A:98:B6:E3:B0     
1716978 7451870 -61 00:3A:98:B6:E3:B0     
1716978 7451870 -63 00:3A:98:B6:E3:B0     
1716978 7451870 -73 00:3A:98:B6:E3:B0     
1716978 7451870 -65 00:3A:98:B6:E3:B0     
1716978 7451869 -54 00:3A:98:B6:E3:B0     
1716977 7451868 -52 00:3A:98:B6:E3:B0     
1716978 7451867 -52 00:3A:98:B6:E3:B0     
1716985 7451866 -52 00:3A:98:B6:E3:B0     
1716990 7451865 -52 00:3A:98:B6:E3:B0     
1716978 7451864 -52 00:3A:98:B6:E3:B0     
1716979 7451863 -52 00:3A:98:B6:E3:B0     
1716979 7451864 -52 00:3A:98:B6:E3:B0     
1716978 7451865 -53 00:3A:98:B6:E3:B0     
1716978 7451865 -44 00:3A:98:B6:E3:B0     
1716978 7451866 -44 00:3A:98:B6:E3:B0

Suppose 1st field is X and 2nd field is Y. If I treat them in a 2 dimensional coordinate system, each record has its own point as X and Y. What I would like to do is to compare each points in each record and report if there is a 5 meter change. I would like to do this using awk and arrays. It will be comparison of each value with the previous one and if there is a change, make an array for changed instances.
Here is my code;

Code:
{
   rssi[FNR]=$3
   mac[FNR]=$4
   pos[FNR]=sqrt(($1^2)+($2^2))
   fnr=FNR
}
END {
        for (i=1;i<=fnr;i++)
        {
                if ((pos[i]-pos[i-1])>5 && (pos[i]-pos[i-1])<-5)
                pos_changed[i]=pos[i]             #I would like to assign changed values into different array.      
        }
        for (i=1;i<=fnr;i++)
        print pos_changed[i]                        #at last, reporting the changes
}

Output of this code is nothing actually, blank page and then command window again...
I think I have a problem in assigning the changed value. I searched a lot in the forum but there is no exact problem, similar but not helpful for my code.

I am looking forward to see your feedbacks again.
Regards.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

A simple Samba problem, please help

Hi, I have successfully setup my Samba server on my Sun Solaris 8 Sparc machine. My Win2000 workstation is able to see the unix worstation and its shared directory from Network Neighborhood. However, the Unix workstation appears as Ip address instead of Hostname on my network neighborhood... (5 Replies)
Discussion started by: champion
5 Replies

2. Shell Programming and Scripting

simple Bourne problem

Hi, I'm a newer for this languages, and I have a log file, which is something like this: 35.75.253.207 - - "GET /products/orgonizer/title.png HTTP/1.1" 200 1555 "-" "Mozilla 1.4" Now, I want to write a shell code to accoplish like ./XXX.sh -N n n is a number by user input, the code should... (5 Replies)
Discussion started by: pnxi
5 Replies

3. UNIX for Dummies Questions & Answers

Simple Array in Ksh Scripting

Ksh Scripting Can some one give me a simple example of array operations using ksh. For Ex: week_array = {Sunday Monday Tuesday Wednesday Thursday Friday Saturday} I want to assign and retrieve and print them along with their index. I am looking for the o/p like: 0 Sunday 1 Monday ... (2 Replies)
Discussion started by: ravikirankethe
2 Replies

4. Shell Programming and Scripting

Simple list file ls to an array

Hi all, Simple question, how can I simply create an array from listing the files in a directory i..e myvar=`ls`; echo $myvar gives a fulllist of files/ directories how can I now convery myvar to an array so I can loop around and read each file/dir? Thnaks CF:) (6 Replies)
Discussion started by: cyberfrog
6 Replies

5. UNIX for Dummies Questions & Answers

simple way to read an array in ksh

hi, I'm a newbie to shell scripting. I wanted to initialise an array using basic for loop and read it. Then i want to print it as a .CSV file.. Any help would me much appreciated.. (1 Reply)
Discussion started by: pravsripad
1 Replies

6. UNIX for Dummies Questions & Answers

simple fork() problem

I have this little program ... int main(void){ printf("Before"); fork(); printf("After"); } output is this..... BeforeAfterBeforeAfter Shouldnt it be.....BeforeAfterAfter After parent is forked child receives the copy of program and continues from next statement... (3 Replies)
Discussion started by: joker40
3 Replies

7. Programming

Simple g++ compilation problem

I'm trying to port some code over to unix Solaris. I'm not really a unix programmer so I'm sure this is something straight-forwards but I'm getting the following: > g++ -c CTrade.cpp In file included from CTrade.cpp:1: stdafx.h:6: warning: `#pragma once' is obsolete CTrade.cpp:4: iostream: No... (1 Reply)
Discussion started by: achartley
1 Replies

8. Shell Programming and Scripting

Please help me with a simple problem

Hi, I have a very simple script like below: for n in 10 20 30 do for a in 30 40 50 60 70 80 do for r in 2 3 4 5 6 7 do m=$((r*a)) count=1 while do echo "a = " $a ", m = " $m ", n = " $n ... (2 Replies)
Discussion started by: Dark2Bright
2 Replies

9. UNIX for Dummies Questions & Answers

LWP::Simple Problem !!

Hi All, I'm having a problem when I run the following code for example perl -e 'use LWP::Simple; getprint "http://google.com"' Can't locate LWP/Simple.pm in @INC (@INC contains: /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6... (7 Replies)
Discussion started by: pawannoel
7 Replies

10. Shell Programming and Scripting

simple wc problem

Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines peter paul john I run the command # var=`grep paul file.txt` # echo $var paul # echo $var | wc -l 1 but when I grep for a value that isnt in the file, i still... (4 Replies)
Discussion started by: rethink
4 Replies
ppmtosixel(1)                                                 General Commands Manual                                                ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 05:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy