sed commands

Example:

nmcli device show | sed -n '/IP4.ADDRESS/p'

Outcome:

$ nmcli device show
...
IP4.ADDRESS[1]:                         192.168.0.2/24
IP4.ADDRESS[2]:                         192.168.0.3/24
...

$ nmcli device show | sed -n '/IP4.ADDRESS/p'
IP4.ADDRESS[1]:                         192.168.0.2/24
IP4.ADDRESS[2]:                         192.168.0.3/24

Example:

nmcli device show | sed -n '/IP4.ADDRESS[0-9]:/p' | sed 's/IP4.ADDRESS[0-9]:\s*//'

Outcome: Given that the content of the nmcli output is not provided, I’ll provide a mock output based on a typical nmcli output:Copy code

192.168.1.10/24 2010.0.2.15/24 20203.0.113.10/24

In this mock output, 203.0.113.10 would be an example of a public IP address, while the others are private IP addresses. The command filters out the IP addresses from the nmcli output.

Conclusion

In system administration, sed commands offer unparalleled utility. Throughout our discussion, we delved deep into the intricacies of sed commands, showcasing their versatility and power. Sed commands stand out as an indispensable tool for administrators, especially when dealing with large volumes of text data.

From simple text replacements to intricate pattern matching, sed commands have proven to be the go-to solution. We’ve seen how these commands can switch words, modify timestamps, and even integrate seamlessly with other Linux tools. Furthermore, following the root requirements ensures that we apply sed commands effectively and maximize their potential.

Furthermore, the examples demonstrated the real-world applicability of sed commands. Whether it’s switching names, altering timestamps, or making selective replacements based on specific matches, sed commands handle it all with finesse.

Additionally, the combination of sed commands with other Linux tools, like ‘nmcli’, exemplifies the adaptability of sed. This adaptability is a testament to why sed commands are a staple in an administrator’s toolkit. In essence, for anyone looking to streamline their text processing tasks on Linux, mastering sed commands is paramount.

So, sed commands are great tools for working with text. They’re used a lot in system administration because they’re efficient and super useful. As we’ve seen, if you know how to use them right, sed commands can make hard tasks easy. This makes things simpler for admins.

More related readings for sed commands:

  1. Sed Command in Linux/Unix with examples – GeeksforGeeks
  2. Sed – An Introduction and Tutorial
  3. The Basics of Using the Sed Stream Editor to Manipulate Text in Linux – DigitalOcean

© Linuxprofessional.ie

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version