Sponsored Content
Top Forums Shell Programming and Scripting Finding when a file switches direction using awk Post 302543977 by bflinchum on Tuesday 2nd of August 2011 03:12:54 PM
Old 08-02-2011
Niether of them worked; the problem was it seemed to pick random points not the peaks (I plotted them using GMT).

Instead of accepting defeat can I trouble you for a little explanation, if I understood the logic a little better I think I could tweak it. I am still new at awk but my professor loves it, and the more I use it the more I realize how powerful it actually is.


Code:
awk 'NR==1{last=$2;lost_row=$1;getline;cur=$2;cur_row=$1;next}

This is the part I don't quite understand. What exactly does NR == 1 accomplish? Your setting the number of rows equal to one? does a ';' seperate commands? So you set last equal to column 2, lost_row equal to column one.
Why do your run a getline? I looked it up and it is defined as:
getline - returns 1 if it finds a record, and 0 if the end of the file is encountered

Anyways I get the feeling that $1 and $2 are now rows above and below not columns?


Code:
  {if (last>=cur&&$2<=cur) print cur_row; 
      last=cur;last_row=cur_row;cur=$2;cur_row=$1}' infile

This part logically makes sense, and this is what I am trying to accomplish.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Tar switches!!!

Hi, If i want to write my data on several tapes, (more than one tape), what switch(s) i need to use with tar. In other word if my data needs the sapce more than one tape & i don't wanna to compress or ... my data. so is it possible to write up to the end of the tape & it asks to put another... (1 Reply)
Discussion started by: nikk
1 Replies

2. UNIX for Dummies Questions & Answers

New & could use some direction!

First, I just rebuilt/installed my custom kernel & I don't know how to check if it ran properly (I'm fairly sure it did, but I'm looking for reassurance that it loaded the new kernel file). Second, I'd love to get into programming, scripting, whatever, I want my imagination to be the builder &... (2 Replies)
Discussion started by: LazySpoon
2 Replies

3. Shell Programming and Scripting

awk script required for finding records in 1 file with corresponding another file.

Hi, I have a .txt file (uniqfields.txt) with 3 fields separated by " | " (pipe symbol). This file contains unique values with respect to all these 3 fields taken together. There are about 40,000 SORTED records (rows) in this file. Sample records are given below. 1TVAO|OVEPT|VO... (2 Replies)
Discussion started by: RRVARMA
2 Replies

4. Shell Programming and Scripting

awk command for finding field in a file

hi guys i have this file with column number 7 as below: 0 1416 49 37 5 3 2 0 0 0 21 0 26 ... (5 Replies)
Discussion started by: npatwardhan
5 Replies

5. Shell Programming and Scripting

re-direction

Say I have a single bin directory with Linux and SunOS executables, like this: bin/myprog_lnx bin/myprog_sun Assume these programs read from stdin and write to stdout and, thus, are meant to be run like this: myprog_lnx < filein > fileout My users may log in from a Linux or Solaris... (3 Replies)
Discussion started by: gsal
3 Replies

6. Fedora

Need Direction for extra work ?

Hey , I have become pretty normal, using unix and what not and working around FEDORA 9 I was wondering does anyone have any IDEAS or have anything I should try to build or scripts to write , or possibly know any sites where I could practice some things just so I know I am writing them... (2 Replies)
Discussion started by: Producer
2 Replies

7. Shell Programming and Scripting

echo switches

Hello All, I am writing an shell script but abruptly its not able to recognize switches in echo statement. #!/bin/bash top -n 1 -b>ankit host=`hostname` time=`cat ankit|grep load|tr -s " "|cut -d " " -f3` load=`cat ankit|grep load|tr -s " "|cut -d "," -f4|cut -d ":" -f2` ... (3 Replies)
Discussion started by: ajaincv
3 Replies

8. Fedora

In need of some direction

Okay, so I'm not a complete newb when it comes to using Unix/Linux. I've been using Ubuntu for a few years now and I've dipped my toes into a few other distros but now I want to get a bit serious. I'm looking at becoming a sysadmin but the trouble is...I have no idea where to start. What I'm... (1 Reply)
Discussion started by: Tamachan87
1 Replies

9. Shell Programming and Scripting

awk print re-direction to a file with timestamp appended

Hello I need to split big xml file into multiple files based on xml declaration. for that i have written one awk 1 liner as below awk '/<?xml\ version/{i++}{print > "outfile."i}' test123.xml this is producing the desired out put. but i want the the currenttimestamp with milliseconds in the... (3 Replies)
Discussion started by: dsdev_123
3 Replies

10. Shell Programming and Scripting

Can I please get a push in the right direction with awk/sed?

Hi Guys, I have this task to monitor a linux box. I found a program that displays the parameters that I want and I wrote a little .sh to run that program and record output into a file. The findings look promising but I would like to graph them. My output (for every iteration) looks like... (3 Replies)
Discussion started by: DraxDomax
3 Replies
SHELL-QUOTE(1p) 					User Contributed Perl Documentation					   SHELL-QUOTE(1p)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.8.4 2005-05-03 SHELL-QUOTE(1p)
All times are GMT -4. The time now is 04:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy