Discussion:
[shell-script] Pegar apenas linhas especificas
andrelucio.fc@yahoo.com [shell-script]
2017-07-25 20:21:31 UTC
Permalink
Opa, pessoal.


Eu preciso os dados das linhas com o conteúdo "lease" e "hardware ethernet", achei a seguinte solução que deu certo: sed -n '/lease/{h;g;p};/hardware/{h;g;p};'dhcp.log. Vocês conhecem alguma outra solução além dessa para pegar os dados de linha especificas?


Dados:


# The format of this file is documented in the dhcpd.leases(5) manual page.


lease 10.0.0.46 {
starts 1 2017/07/17 18:20:50;
ends 1 2017/07/17 19:04:07;
tstp 1 2017/07/17 19:04:07;
cltt 1 2017/07/17 18:20:50;
binding state free;
hardware ethernet b3:bb:1f:22:2a:61;
}
lease 10.0.0.50 {
starts 1 2017/07/17 18:30:08;
ends 1 2017/07/17 20:30:08;
tstp 1 2017/07/17 20:30:08;
cltt 1 2017/07/17 18:30:08;
binding state free;
hardware ethernet 2a:cc:cc:d1:ab:cf;
}
lease 10.0.0.48 {
starts 5 2017/07/21 14:12:20;
ends 5 2017/07/21 16:12:20;
tstp 5 2017/07/21 16:12:20;
cltt 5 2017/07/21 14:12:20;
binding state free;
hardware ethernet 1d:aa:fd:31:0b:0a;
}
lease 10.0.0.40 {
starts 5 2017/07/14 13:44:36;
ends 5 2017/07/21 13:44:36;
tstp 5 2017/07/21 13:44:36;
cltt 5 2017/07/14 13:44:36;
binding state free;
hardware ethernet 11:30:xd:b3:xx:da;
Raul Libório rauhmaru@gmail.com [shell-script]
2017-07-25 20:24:13 UTC
Permalink
egrep 'lease|hardware ethernet'
Post by ***@yahoo.com [shell-script]
Opa, pessoal.
Eu preciso os dados das linhas com o conteúdo "lease" e "hardware
ethernet", achei a seguinte solução que deu certo: sed -n
'/lease/{h;g;p};/hardware/{h;g;p};'dhcp.log. Vocês conhecem alguma outra
solução além dessa para pegar os dados de linha especificas?
# The format of this file is documented in the dhcpd.leases(5) manual page.
lease 10.0.0.46 {
starts 1 2017/07/17 18:20:50;
ends 1 2017/07/17 19:04:07;
tstp 1 2017/07/17 19:04:07;
cltt 1 2017/07/17 18:20:50;
binding state free;
hardware ethernet b3:bb:1f:22:2a:61;
}
lease 10.0.0.50 {
starts 1 2017/07/17 18:30:08;
ends 1 2017/07/17 20:30:08;
tstp 1 2017/07/17 20:30:08;
cltt 1 2017/07/17 18:30:08;
binding state free;
hardware ethernet 2a:cc:cc:d1:ab:cf;
}
lease 10.0.0.48 {
starts 5 2017/07/21 14:12:20;
ends 5 2017/07/21 16:12:20;
tstp 5 2017/07/21 16:12:20;
cltt 5 2017/07/21 14:12:20;
binding state free;
hardware ethernet 1d:aa:fd:31:0b:0a;
}
lease 10.0.0.40 {
starts 5 2017/07/14 13:44:36;
ends 5 2017/07/21 13:44:36;
tstp 5 2017/07/21 13:44:36;
cltt 5 2017/07/14 13:44:36;
binding state free;
hardware ethernet 11:30:xd:b3:xx:da;
--
Raul Libório
http://rauhmaru.blogspot.com/
openSUSE Member | Linux User #4444581

/etc/httpd/conf.d/ssl.conf:7
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
Cleiton Alves cleitondebian@gmail.com [shell-script]
2017-07-25 20:26:14 UTC
Permalink
Com egrep acho que você consegue tranquilamente ,exemplo


egrep -i "lease|hardware|ethernet" file.log


Abs
Post by ***@yahoo.com [shell-script]
Opa, pessoal.
Eu preciso os dados das linhas com o conteúdo "lease" e "hardware
ethernet", achei a seguinte solução que deu certo: sed -n
'/lease/{h;g;p};/hardware/{h;g;p};'dhcp.log. Vocês conhecem alguma outra
solução além dessa para pegar os dados de linha especificas?
# The format of this file is documented in the dhcpd.leases(5) manual page.
lease 10.0.0.46 {
starts 1 2017/07/17 18:20:50;
ends 1 2017/07/17 19:04:07;
tstp 1 2017/07/17 19:04:07;
cltt 1 2017/07/17 18:20:50;
binding state free;
hardware ethernet b3:bb:1f:22:2a:61;
}
lease 10.0.0.50 {
starts 1 2017/07/17 18:30:08;
ends 1 2017/07/17 20:30:08;
tstp 1 2017/07/17 20:30:08;
cltt 1 2017/07/17 18:30:08;
binding state free;
hardware ethernet 2a:cc:cc:d1:ab:cf;
}
lease 10.0.0.48 {
starts 5 2017/07/21 14:12:20;
ends 5 2017/07/21 16:12:20;
tstp 5 2017/07/21 16:12:20;
cltt 5 2017/07/21 14:12:20;
binding state free;
hardware ethernet 1d:aa:fd:31:0b:0a;
}
lease 10.0.0.40 {
starts 5 2017/07/14 13:44:36;
ends 5 2017/07/21 13:44:36;
tstp 5 2017/07/21 13:44:36;
cltt 5 2017/07/14 13:44:36;
binding state free;
hardware ethernet 11:30:xd:b3:xx:da;
--
Att:
Cleiton Alves
Raul Libório rauhmaru@gmail.com [shell-script]
2017-07-25 20:50:41 UTC
Permalink
Pra ficar bonito:

awk '/lease /||/hardware ethernet/{gsub(/ {/,""); print $1,$2,$3}' dhcp.log
| paste -d' ' - -
Post by Cleiton Alves ***@gmail.com [shell-script]
Com egrep acho que você consegue tranquilamente ,exemplo
egrep -i "lease|hardware|ethernet" file.log
Abs
Post by ***@yahoo.com [shell-script]
Opa, pessoal.
Eu preciso os dados das linhas com o conteúdo "lease" e "hardware
ethernet", achei a seguinte solução que deu certo: sed -n
'/lease/{h;g;p};/hardware/{h;g;p};'dhcp.log. Vocês conhecem alguma outra
solução além dessa para pegar os dados de linha especificas?
# The format of this file is documented in the dhcpd.leases(5) manual page.
lease 10.0.0.46 {
starts 1 2017/07/17 18:20:50;
ends 1 2017/07/17 19:04:07;
tstp 1 2017/07/17 19:04:07;
cltt 1 2017/07/17 18:20:50;
binding state free;
hardware ethernet b3:bb:1f:22:2a:61;
}
lease 10.0.0.50 {
starts 1 2017/07/17 18:30:08;
ends 1 2017/07/17 20:30:08;
tstp 1 2017/07/17 20:30:08;
cltt 1 2017/07/17 18:30:08;
binding state free;
hardware ethernet 2a:cc:cc:d1:ab:cf;
}
lease 10.0.0.48 {
starts 5 2017/07/21 14:12:20;
ends 5 2017/07/21 16:12:20;
tstp 5 2017/07/21 16:12:20;
cltt 5 2017/07/21 14:12:20;
binding state free;
hardware ethernet 1d:aa:fd:31:0b:0a;
}
lease 10.0.0.40 {
starts 5 2017/07/14 13:44:36;
ends 5 2017/07/21 13:44:36;
tstp 5 2017/07/21 13:44:36;
cltt 5 2017/07/14 13:44:36;
binding state free;
hardware ethernet 11:30:xd:b3:xx:da;
--
Cleiton Alves
--
Raul Libório
http://rauhmaru.blogspot.com/
openSUSE Member | Linux User #4444581

/etc/httpd/conf.d/ssl.conf:7
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
Continue reading on narkive:
Loading...