samedi 29 février 2020

use if loop in awk command unix

#!/bin/bash

read -p "enter 2nd longtitude: " lon2;read -p "enter 2nd latitude: " lat2;read -p "enter 4th longtitude: " lon4;\
read -p "enter 4th latitude: " lat4;read -p "enter date of major earthquake (yy-mm-dd): " date;read -p "insert time of birth (hr:min:sec): " time;\
read -p "insert days after earthquake: " n

year=`echo $date|cut -d "-" -f 1`;month=`echo $date|cut -d "-" -f 2`;day=`echo $date|cut -d "-" -f 3`\
hr=`echo $time|cut -d ":" -f 1`;min=`echo $time|cut -d ":" -f 2`;sec=`echo $time|cut -d ":" -f 3`

head -n 8 finalcat.cat>titlos;sed '1,8d' finalcat.cat>arxeio

awk -v lon4=$lon4 -v lon2=$lon2 -v lat2=$lat2 -v lat4=$lat4 '{lon=$4;lat=$3}{if(lon<lon2 && lon>lon4 && lat>lat4 && lat<lat2) print $0}' arxeio>teliko1

while read line ;do
hrr=`echo $line|awk -F " " '{print $2}'|awk -F ":" '{print $1}'`; minn=`echo $line|awk -F " " '{print $2}'|awk -F ":" '{print $2}'`
secc=`echo $line|awk -F " " '{print $2}'|awk -F ":" '{print $3}'`; yearr=`echo $line|awk -F " " '{print $1}'|awk -F "-" '{print $1}'`
monthh=`echo $line|awk -F " " '{print $1}'|awk -F "-" '{print $2}'`; dayy=`echo $line|awk -F " " '{print $1}'|awk -F "-" '{print $3}'`
done<arxeio

awk -v hrr=$hrr -v minn=$minn -v secc=$secc -v yearr=$yearr -v monthh=$month -v dayy=$dayy -v year=$year -v month=$month -v day=$day -v hr=$hr -v min=$min -v sec=$sec -v n=$n '{if( (yearr==year && monthh==month && dayy==day && hrr>=hr && minn>=min && secc>=sec) || (yearr==year && monthh==month && dayy>day && dayy<day+n) || (yearr==year && monthh==month && dayy==day+n && hrr<=hr && minn<=min && secc<=sec) ) print $0}' teliko1 |sort -k 6n> teliko2

it doesnt work. It just stopps without executing the code. Is it something wrong with my code? thanks!

Aucun commentaire:

Enregistrer un commentaire