0

I need help with my Linux laboratories. Does anybody know a combination of command complies with this exercise?

Look at the output of /sbin/ifconfig. Write a line that only displays IP address and the subnet mask. (use head; grep; tr -s; cut; )

This what is what I got so far:

/sbin/ifconfig | grep -w "inet"
2
  • Homework works best if you solve it yourself. What is your expected output?
    – Panki
    Mar 23, 2020 at 16:19
  • Honestly speaking I have no idea. I think it is supposed to be something like address mask Mar 23, 2020 at 16:28

2 Answers 2

0

I believe this would acheive the desired effect

/sbin/ifconfig | grep -Po '(?<=\binet )[^/]+/\w+|(?<=\binet6 )[^/]+/\w+'

3
  • Your answer helped me a lot. In the end, I used it to write this command: /sbin/ifconfig | grep -P '((?<=\binet )[^ ]+)|((?<=\bnetmask )[^ ]+)' | head -1. Without your help I would stuck forever. Mar 23, 2020 at 17:28
  • I was guessing ifconfig's output was the same as IP address show, obviously it's not. sorry @Krystofer125
    – Grump
    Mar 23, 2020 at 17:54
  • No problem, I figured it out. Mar 23, 2020 at 18:05
0

It's a shame you can't use awk

ifconfig -a eth0|grep -w inet |awk '{print $2, $4}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .