Skip to content
Advertisement

How to print IP address from Shell Script?

Below is my command line

JavaScript

I want to get output of IP address(10.1.2.133) alone as output. How to write command line for that?

Advertisement

Answer

If you don’t mind a solution which is not elegant, but does the job, just pipe the output of your grep command into

JavaScript

This splits the line first by the = and then :. If the pattern is not so regular and the IP address can appear anywhere in the line, pipe it into

JavaScript

The -o option just extract the matching pattern(s) from the input.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement