Reputation: 739
I am new to the Scripting
#!/bin/bash
#set -x
cat /proc/net/dev > net
while read -r line
do
tx_bytes=$(echo $line | tac | head -n1 | awk '{print $2}')
echo $tx_bytes
done <net
I want to store the tx bytes into the tx_byte variable. when i tried the above script its printing all the lines which are there in net file.
net file.
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
wlp9s0b1: 180051861 145907 0 0 0 0 0 0 13205537 85626 0 0 0 0 0 0
lo: 4136388 45561 0 0 0 0 0 0 4136388 45561 0 0 0 0 0 0
enp5s0: 11824249235 9325207 0 1 0 0 0 0 364193641 4070320 0 0 0 0 0 0
Upvotes: 0
Views: 181
Reputation: 88583
Print value from last line:
awk 'END{print $2}' /proc/net/dev
Print value from second column with enp5s0:
in first column.
awk '$1=="enp5s0:" {print $2}' /proc/net/dev
Upvotes: 3