LIBRARY

BACK TO TUTORIALS SECTION

USING AWK

Q: I want to make a fledermaus sd file using only data in 'data.dat' that has a zero in column 6. How do I do that?
A: To use only data that has a zero in column 6:
awk '$6==0{print $1, $2, -1e3*$3, $5}' data.dat > junk.dat 
mkpoint3d -in junk.dat -type ascii -format "y x z time"
-out eq_time.sd /usr/bin/rm junk.dat

Similarly to use only data that has a one in column 6:


awk '$6==1{print $1, $2, -1e3*$3}' data.dat > junk.dat 
mkpoint3d -in junk.dat -type ascii -format "y x z time" 
-out eq_time.sd /usr/bin/rm junk.dat

Q: How do I spit out the last two columns of a file.dat?
A: Use the following awk command:
awk '{ print $(NF-2), $(NF-1)}' file.dat

Awk commands

Goal:
From a lengthy data list slurp out only data from a given x, y, z range based on a favorite center point and allowable bounds around the center point.

#!/bin/bash

#

#

dx=.02

dy=.02

dz=.8

yat=36.625

xat=-121.23

zat=3.14

x1=`echo $xat-$dx | bc`

x2=`echo $xat+$dx | bc`

y1=`echo $yat-$dy | bc`

y2=`echo $yat+$dy | bc`

z1=`echo $zat-$dz | bc`

z2=`echo $zat+$dz | bc`

 

echo 'hi'

echo "x1, x2, y1, y2, z1, z2:" $x1 , $x2 , $y1 , $y2 , $z1 , $z2

wc SAF_locfoc_HASH.dat

#awk '"$y1"<$2{print $0}' SAF_locfoc_HASH.dat | wc

#awk '36.425<$2 {print $0}' SAF_locfoc_HASH.dat | wc

 

echo "y2: " $y2

awk '36.645>$2 {print $0}' SAF_locfoc_HASH.dat | wc

awk -v y2="$y2" -v y1="$y1" -v x1="$x1" 
-v x2="$x2" -v z1="$z1" -v z2="$z2" \

'x1<-$3&&x2>-$3&&y1<$2&&y2>$2&&z1<$4&&z2>$4{print $0}
' SAF_locfoc_HASH.dat


Goal:
Separate into 2 files - one that has a 0 in column 6, and the other that has a 1 in column 6
#

#  This is wrt cluster

#

/usr/bin/rm junk0.dat  junk1.dat

awk '$6==0{print $1, $2, -1e3*$3, $6}' 
/myfiles/dataA.dat  >junk0.dat &

awk '$6==1{print $1, $2, -1e3*$3, $6}' 
/myfiles/dataB.dat  >junk1.dat &  

Goal:
Set the delemeter to a `,` & only look for data where column 28 is not an "R"
Code:
awk -F '\,' '{if ($28 != "R") print $17,$20,-1e3*$26,$9}'
data_new.dat > data_cut_meters.dat

Goal:
Convert an img file to a grd file.
Code:
img2grd /myfiles/raw_data/topo_8.2.img 
-R170/176/-43/-39 -GNZ.grd -T1 -M -V