Filtering ifconfig outputHow exactly do people “crack” Unix/Linux Systems?nmap script needed to output...

How the name "craqueuhhe" is read

Using Images for Points in ListPlot

Why would guns not work in the dungeon?

Crowbar circuit causes unexpected behavior for op amp circuit

Steampunk helicopter

Do native speakers use ZVE or CPU?

Correct use of ergeben?

Supporting developers who insist on using their pet language

Why does Hellboy file down his horns?

How did the hit man miss?

Would letting a multiclass character rebuild their character to be single-classed be game-breaking?

Trying to find a flaw in my proof that there are more rearrangements of an infinite series than real numbers

Why can't supermassive black holes merge? (or can they?)

Dropping outliers based on "2.5 times the RMSE"

Using ”as” after dialogue tags

As the Dungeon Master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?

As a DM, how to avoid unconscious metagaming when dealing with a high AC character?

Bishop game - python

diff shows a file that does not exist

When did the Roman Empire fall according to contemporaries?

Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?

Was the Ford Model T black because of the speed black paint dries?

Why do players in the past play much longer tournaments than today's top players?

Cops: The Hidden OEIS Substring



Filtering ifconfig output


How exactly do people “crack” Unix/Linux Systems?nmap script needed to output text into csv formatText to yaml conversionUse awk to insert a line after N outputPrint a line in stdout that matches an expression if the output contains another expressionSubset data with awkGrep multiple patterns and print a different number of lines below each of the patterns?Awk field printing within the ternary operatorMakefile cppUtest output reformatPrint specific range of lines between two matches starting with a specific line after the first match






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Im trying to select the First 3 octets of the IPv4 IP from ifconfig. How would i go about doing this. I just cant figure out how to select from this step



[root@hostname ~]# ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}'


Output:



addr:10.20.1.3


what i ultimately want is 10.20.1 for final output










share|improve this question
















bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • BTW, the output of the newer ip addr is easier to parse.

    – dirkt
    Jul 12 '17 at 5:13


















0















Im trying to select the First 3 octets of the IPv4 IP from ifconfig. How would i go about doing this. I just cant figure out how to select from this step



[root@hostname ~]# ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}'


Output:



addr:10.20.1.3


what i ultimately want is 10.20.1 for final output










share|improve this question
















bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • BTW, the output of the newer ip addr is easier to parse.

    – dirkt
    Jul 12 '17 at 5:13














0












0








0








Im trying to select the First 3 octets of the IPv4 IP from ifconfig. How would i go about doing this. I just cant figure out how to select from this step



[root@hostname ~]# ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}'


Output:



addr:10.20.1.3


what i ultimately want is 10.20.1 for final output










share|improve this question
















Im trying to select the First 3 octets of the IPv4 IP from ifconfig. How would i go about doing this. I just cant figure out how to select from this step



[root@hostname ~]# ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}'


Output:



addr:10.20.1.3


what i ultimately want is 10.20.1 for final output







linux awk sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 6 '17 at 3:40









heemayl

37.6k3 gold badges82 silver badges110 bronze badges




37.6k3 gold badges82 silver badges110 bronze badges










asked Jul 5 '17 at 23:48









CasMzCasMz

61 bronze badge




61 bronze badge





bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • BTW, the output of the newer ip addr is easier to parse.

    – dirkt
    Jul 12 '17 at 5:13



















  • BTW, the output of the newer ip addr is easier to parse.

    – dirkt
    Jul 12 '17 at 5:13

















BTW, the output of the newer ip addr is easier to parse.

– dirkt
Jul 12 '17 at 5:13





BTW, the output of the newer ip addr is easier to parse.

– dirkt
Jul 12 '17 at 5:13










3 Answers
3






active

oldest

votes


















0














Assuming you are looking for the IP address of eth0, this should do it:



ifconfig | grep -A1 eth0 | grep "inet addr" | sed 's/inet addr://' | awk '{ print $1 }' | sed 's/.[0-9]*$//'





share|improve this answer































    0














    Using only awk, for all interfaces:



    ifconfig | awk '/Link encap/{eth=$1} ; /inet addr/{sub(/addr:/, "", $2) ; sub(/.[0-9]*$/,"",$2) ; addr=$2 ; print eth, addr)'


    Results:



    eth0 192.168.0
    lo 127.0.0





    share|improve this answer































      0














      I wouldn't even bother using sed for the actual address. It's more transparent (and easier to get right) to use cut for this!



      Add | sed -e 's/inet_addr://' | cut -d. -f 1-3 to the end of your original command:



      ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}' | sed -e 's/inet_addr://' | cut -d. -f 1-3  


      Or just use cut instead of awk:



      ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | cut -w -f 2 | sed -e 's/inet_addr://' | cut -d. -f 1-3  





      share|improve this answer


























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "106"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f375614%2ffiltering-ifconfig-output%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        Assuming you are looking for the IP address of eth0, this should do it:



        ifconfig | grep -A1 eth0 | grep "inet addr" | sed 's/inet addr://' | awk '{ print $1 }' | sed 's/.[0-9]*$//'





        share|improve this answer




























          0














          Assuming you are looking for the IP address of eth0, this should do it:



          ifconfig | grep -A1 eth0 | grep "inet addr" | sed 's/inet addr://' | awk '{ print $1 }' | sed 's/.[0-9]*$//'





          share|improve this answer


























            0












            0








            0







            Assuming you are looking for the IP address of eth0, this should do it:



            ifconfig | grep -A1 eth0 | grep "inet addr" | sed 's/inet addr://' | awk '{ print $1 }' | sed 's/.[0-9]*$//'





            share|improve this answer













            Assuming you are looking for the IP address of eth0, this should do it:



            ifconfig | grep -A1 eth0 | grep "inet addr" | sed 's/inet addr://' | awk '{ print $1 }' | sed 's/.[0-9]*$//'






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 6 '17 at 0:08









            Timothy MartinTimothy Martin

            5,58425 silver badges30 bronze badges




            5,58425 silver badges30 bronze badges

























                0














                Using only awk, for all interfaces:



                ifconfig | awk '/Link encap/{eth=$1} ; /inet addr/{sub(/addr:/, "", $2) ; sub(/.[0-9]*$/,"",$2) ; addr=$2 ; print eth, addr)'


                Results:



                eth0 192.168.0
                lo 127.0.0





                share|improve this answer




























                  0














                  Using only awk, for all interfaces:



                  ifconfig | awk '/Link encap/{eth=$1} ; /inet addr/{sub(/addr:/, "", $2) ; sub(/.[0-9]*$/,"",$2) ; addr=$2 ; print eth, addr)'


                  Results:



                  eth0 192.168.0
                  lo 127.0.0





                  share|improve this answer


























                    0












                    0








                    0







                    Using only awk, for all interfaces:



                    ifconfig | awk '/Link encap/{eth=$1} ; /inet addr/{sub(/addr:/, "", $2) ; sub(/.[0-9]*$/,"",$2) ; addr=$2 ; print eth, addr)'


                    Results:



                    eth0 192.168.0
                    lo 127.0.0





                    share|improve this answer













                    Using only awk, for all interfaces:



                    ifconfig | awk '/Link encap/{eth=$1} ; /inet addr/{sub(/addr:/, "", $2) ; sub(/.[0-9]*$/,"",$2) ; addr=$2 ; print eth, addr)'


                    Results:



                    eth0 192.168.0
                    lo 127.0.0






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 6 '17 at 0:53









                    nxr_jivranxr_jivra

                    235 bronze badges




                    235 bronze badges























                        0














                        I wouldn't even bother using sed for the actual address. It's more transparent (and easier to get right) to use cut for this!



                        Add | sed -e 's/inet_addr://' | cut -d. -f 1-3 to the end of your original command:



                        ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}' | sed -e 's/inet_addr://' | cut -d. -f 1-3  


                        Or just use cut instead of awk:



                        ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | cut -w -f 2 | sed -e 's/inet_addr://' | cut -d. -f 1-3  





                        share|improve this answer




























                          0














                          I wouldn't even bother using sed for the actual address. It's more transparent (and easier to get right) to use cut for this!



                          Add | sed -e 's/inet_addr://' | cut -d. -f 1-3 to the end of your original command:



                          ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}' | sed -e 's/inet_addr://' | cut -d. -f 1-3  


                          Or just use cut instead of awk:



                          ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | cut -w -f 2 | sed -e 's/inet_addr://' | cut -d. -f 1-3  





                          share|improve this answer


























                            0












                            0








                            0







                            I wouldn't even bother using sed for the actual address. It's more transparent (and easier to get right) to use cut for this!



                            Add | sed -e 's/inet_addr://' | cut -d. -f 1-3 to the end of your original command:



                            ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}' | sed -e 's/inet_addr://' | cut -d. -f 1-3  


                            Or just use cut instead of awk:



                            ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | cut -w -f 2 | sed -e 's/inet_addr://' | cut -d. -f 1-3  





                            share|improve this answer













                            I wouldn't even bother using sed for the actual address. It's more transparent (and easier to get right) to use cut for this!



                            Add | sed -e 's/inet_addr://' | cut -d. -f 1-3 to the end of your original command:



                            ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | awk '{print $2}' | sed -e 's/inet_addr://' | cut -d. -f 1-3  


                            Or just use cut instead of awk:



                            ifconfig | grep "inet addr:"  | grep -v "127.0.0.1" | cut -w -f 2 | sed -e 's/inet_addr://' | cut -d. -f 1-3  






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jul 11 '17 at 23:17









                            Bob EagerBob Eager

                            2,1111 gold badge5 silver badges23 bronze badges




                            2,1111 gold badge5 silver badges23 bronze badges






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f375614%2ffiltering-ifconfig-output%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...