0

I can get Receive and Transmit bytes for an android device as follows

130|sailfish:/ $ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
rmnet_ipa0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
r_rmnet_data7:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
r_rmnet_data4:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet_data1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet_data3:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
 wlan0: 6720980481 66560024    0    0    0     0          0         0 355572166 1127583    0    2    0     0       0          0
rmnet_data5:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
r_rmnet_data1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

Further, I am trying to filter the received and transmit bytes for an Android device using

cat /proc/net/dev |grep wlan | awk {'print $1'}

but I get the following error

/system/bin/sh: awk: not found

Any alternative way to select the appropriate columns?


I tried Perl as well as

cat /proc/net/dev | grep wlan   | perl -lane 'print $F[1]' 

which gave

/system/bin/sh: perl: not found

using cut as

cat /proc/net/dev | grep wlan   | cut  -d' ' -f3  

gives

6720980481

but the issues is that I want to cut the tab instead of space as I want to select other tabs as well

I tried

cat /proc/net/dev | grep wlan   | cut  -d'\t' -f3   

and

cat /proc/net/dev | grep wlan   | cut  -d'    ' -f3 

but it gives

cut: the delimiter must be a single character
Amarjit Dhillon
  • 2,718
  • 3
  • 23
  • 62
  • the fact that some tool is not available to you is not the reason to put it in the title and list it as a tag. – Alex P. Apr 29 '18 at 13:23

1 Answers1

-1

I guess one of the solutions would be to try and install awk and/or perl, but I guess that can't be done for some reason. Anyway, tab is the default separator character in cut. So this should work

cat /proc/net/dev | grep wlan   | cut -f3
jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • 1
    OP can not tell a part consecutive spaces from tabs. What he wanted was `grep wlan /proc/net/dev | tr -s ' ' | cut -d' ' -f3`. – Alex P. Apr 29 '18 at 13:30
  • @jjmerelo : the output of `cat /proc/net/dev | grep wlan | cut -f3 ` is same as that of `cat /proc/net/dev |grep wlan ` – Amarjit Dhillon Apr 29 '18 at 15:12
  • @AlexP. : you are right, your script worked, you can provide it as an answer. Can you please tell me how can I select both `-f3` and `-f11` – Amarjit Dhillon Apr 29 '18 at 15:15
  • @AlexP. The OP mentions '\t' in one of his/her examples, and talks about "cut the tab". Your code is OK as long as it's only spaces and not tabs. – jjmerelo Apr 29 '18 at 16:06
  • @AmarjitSingh That would happen if, as said above, it's spaces and not tabs. I just thought it was tabs as mentioned there. – jjmerelo Apr 29 '18 at 16:07