jueves, 5 de febrero de 2015

awk practice


find a match and print  line after and befoe a delimiter  101-201
 grep -i 101 /home/phpagi-2.20/info.conf |  awk  -F '-' '{ print $2}'      // print after delimiter, 202

 grep -i 101 /home/phpagi-2.20/info.conf |  awk  -F '-' '{ print $1}' // before delimiter print 101 



root@asterisk-dominicana:~# asterisk -x " sip show peers " | grep -i ok > /root/peer.info

root@asterisk-dominicana:~# awk  '{ print $6 }' /root/peer.info
25657
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK

root@asterisk-dominicana:~# awk  -F '/' '{ print $1 }' /root/peer.info
100
CommPeak
australia
callcentric
comk
didlogic
fongo
nick1
perment                   216.53.4.1                                  No         No             5060     OK (3 ms)
rapidvox
skymax



root@asterisk-dominicana:~# asterisk -x " core show channels verbose" | awk '{print $9}'
Duration
00:00:20
00:00:20

root@asterisk-dominicana:~# asterisk -x " core show channels verbose" |grep -i 100 | awk '{print $9}'
00:00:09



root@asterisk-dominicana:~# asterisk -x " sip show peer 100" | grep -i status | awk '{print $3}'
OK

root@asterisk-dominicana:~# asterisk -x " sip show peer 102" | grep -i status | awk '{print $3}'
UNKNOWN

root@asterisk-dominicana:~# asterisk -x " sip show peers" | awk -F '/' '{print $1}' | awk '{print $1}'
Name
100
101
102
103
104
105
106
107
108
109
110
111
CommPeak
australia
callcentric
comk
didlogic
fongo
frantz
nick1
perment
rapidvox
skymax
23

root@asterisk-dominicana:~#  asterisk -rx " sip show registry"  | awk '{print $5}' | grep -i Registered
Registered
Registered
Registered
Registered


root@asterisk-dominicana:~#  asterisk -rx " sip show registry"  | awk '{print $5}' | grep -i Registered | wc -l
4


root@asterisk-dominicana:~# asterisk -x " sip show registry" | grep -i 17772651651 |  awk '{print $5}'
Registered
***************************
# asterisk -x " core show channels"

Channel              Location             State   Application(Data)
0 active channels
0 active calls

14 calls processed

 asterisk -x " core show channels"  |  grep -i calls  |awk 'NR==1' |  awk '{print $1}'
get the number of calls


--------------------
 asterisk -x  "core show hint 100" | awk '{print $1 $4}'  |awk 'NR==1'
100@ext-localState:InUse

print  line  colum 1 and  4 and only the first line

**************************

list only online peer name removing  /
asterisk -x " sip show peers" | grep -w OK | awk '{print $1}' | awk -F'/' '{print $1}'

root@click2call:~# date
Tue Apr  7 02:20:32 AST 2015

to get just the  hour and min
date | awk '{print $4}' |  cut -c1-5


GET the second line of awk

df -h  | awk '{print $5}'  | awk 'NR==2'


http://www.shellhacks.com/en/Printing-Specific-Columns-Fields-in-Bash-using-AWK

http://how-to.linuxcareer.com/learning-linux-commands-awk

No hay comentarios:

Publicar un comentario