Local minima


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Local minima
# 1  
Old 05-22-2010
Local minima

I have a file with a single column of numbers. Starting from the 11th line, I'd like to find the line(s) on which the number meets two criteria: 1) it is less than the 10 numbers that precede it, 2) it is less than the number that follows it. So, for the following, the script should return line 18. I can't think of way of doing this without a grotesquely long 'if' statement.

(start of file)
69.9776
69.8288
69.5982
69.1929
68.7545
68.4256
67.9714
67.3566
66.76
65.9346
65.1717
64.2631
63.3557
62.0736
60.8232
59.9634
59.1894
58.3003
58.4929
59.6617
59.987
...

Thanks!
# 2  
Old 05-22-2010
try this:
Code:
awk '
     { arr[NR]=$0
       if(NR<11) 
          {next}
       val=NR-1
       retval=(arr[NR]>arr[val])? 1: 0
       for(i=val -10; i<val && retval; i++)
       {
          if(arr[i]<=arr[val]) 
              {retval=0 }
       }
       if(retval)
         { print arr[val] }
       } ' inputfile > outputfile

# 3  
Old 05-22-2010
Thanks a lot!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Local DNS

I am trying to install a replacement mail server. On the old machine, nslookup example.com returns 192.168.100.5 instead of its real ip of 207.139...... On the new machine, which I have presumably set up the same way; I compared the data in the gui dnsconfig on both machines, I get an error... (0 Replies)
Discussion started by: jgt
0 Replies

2. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

3. UNIX for Dummies Questions & Answers

Local User

How to fetch only local user without duplication from /etc/passwd using scripting?? (4 Replies)
Discussion started by: AhmedLakadkutta
4 Replies

4. IP Networking

Local network?

I have two PCs, witch have Linux Ubuntu. I want to connect those computers by a local network, but I know right anything about the network. I have a modem (not router) and a router that i don't use. The desktop pc have 2 network cards. (eth0 eth1). The modem is on eth1. Anyone help me!... (4 Replies)
Discussion started by: mghis
4 Replies

5. AIX

Do I need to configure my local windows to FTP files from local windows to a UNIX AIX server?

Hi Friends, I have this script for ftping files from AIX server to local windows xp. #!/bin/sh HOST='localsystem.net' USER='myid_onlocal' PASSWD='mypwd_onlocal' FILE='file.txt' ##This is a file on server(AIX) ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD put $FILE... (1 Reply)
Discussion started by: rajsharma
1 Replies

6. UNIX for Dummies Questions & Answers

local user ip

how can i find my own ip address from unix. command like who -x .this would provide all the ip address but i need to list only current user ip address. who am i command does not display the ip. (1 Reply)
Discussion started by: naushad
1 Replies

7. Linux

rc.local

Hi Hope someone can help, i have no knowledge of Linux but have aquired a script that i am trying to modify to run in an Altiris environment. The script is a bash menu that runs via a linux pxe boot option. when i run the script i get an error saying syntax error near unexpected token... (1 Reply)
Discussion started by: stewfo
1 Replies

8. IP Networking

local proxy

Are there any free local proxy for Linux which cache data and gzip transmitted packages? (5 Replies)
Discussion started by: Hitori
5 Replies

9. UNIX for Dummies Questions & Answers

local host

Dear Guys , Please again , i could not find a solution for my server linux red hat 9 . when i leave it about more than 5 min ideal it goes to something like sleep mode and all services stop and even TCP/IP .. what shall i do ??? another thing please , when i installed the server , i gave... (3 Replies)
Discussion started by: tamemi
3 Replies

10. UNIX for Dummies Questions & Answers

why i have local.profile, local.cshrc,local.login instead of .profile, .login ?

Hello again ! Thanks for response of my first question. there is my second quesiton why i have local.profile instead of .profile file ? my all files in pwd shoes local. before any file. is anybody can tell me about that ? Thanks Abid Malik (5 Replies)
Discussion started by: abidmalik
5 Replies
Login or Register to Ask a Question