extract field from file using sed or awk

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have bash script to collect all hardware info but following memory info piece is missing, so this is what i am trying to do.



Following command give you status of DIMM memory module,



[root@Linux ~]# hpasmcli -s 'show dimm'

DIMM Configuration
------------------
Processor #: 1
Module #: 1
Present: Yes
Form Factor: 9h
Memory Type: DDR3(18h)
Size: 8192 MB
Speed: 1333 MHz
Supports Lock Step: No
Configured for Lock Step: No
Status: Ok

Processor #: 1
Module #: 12
Present: Yes
Form Factor: 9h
Memory Type: DDR3(18h)
Size: 8192 MB
Speed: 1333 MHz
Supports Lock Step: No
Configured for Lock Step: No
Status: Ok

Processor #: 2
Module #: 1
Present: Yes
Form Factor: 9h
Memory Type: DDR3(18h)
Size: 8192 MB
Speed: 1333 MHz
Supports Lock Step: No
Configured for Lock Step: No
Status: Ok

Processor #: 2
Module #: 12
Present: Yes
Form Factor: 9h
Memory Type: DDR3(18h)
Size: 8192 MB
Speed: 1333 MHz
Supports Lock Step: No
Configured for Lock Step: No
Status: DIMM is degraded


want to extract Size: and Status: and need that in single line, like following



Final output will look like following. I can use other language like python or perl but i wrote in bash so i need something in bash, i can do multiple for loop and play with variable to make it work but i need something easy or in-short single like like sed/awk. how can i achieve that in sed/awk?



8192MB - Ok
8192MB - OK
8192MB - OK
8192MB - DIMM is degraded








share



























    up vote
    0
    down vote

    favorite












    I have bash script to collect all hardware info but following memory info piece is missing, so this is what i am trying to do.



    Following command give you status of DIMM memory module,



    [root@Linux ~]# hpasmcli -s 'show dimm'

    DIMM Configuration
    ------------------
    Processor #: 1
    Module #: 1
    Present: Yes
    Form Factor: 9h
    Memory Type: DDR3(18h)
    Size: 8192 MB
    Speed: 1333 MHz
    Supports Lock Step: No
    Configured for Lock Step: No
    Status: Ok

    Processor #: 1
    Module #: 12
    Present: Yes
    Form Factor: 9h
    Memory Type: DDR3(18h)
    Size: 8192 MB
    Speed: 1333 MHz
    Supports Lock Step: No
    Configured for Lock Step: No
    Status: Ok

    Processor #: 2
    Module #: 1
    Present: Yes
    Form Factor: 9h
    Memory Type: DDR3(18h)
    Size: 8192 MB
    Speed: 1333 MHz
    Supports Lock Step: No
    Configured for Lock Step: No
    Status: Ok

    Processor #: 2
    Module #: 12
    Present: Yes
    Form Factor: 9h
    Memory Type: DDR3(18h)
    Size: 8192 MB
    Speed: 1333 MHz
    Supports Lock Step: No
    Configured for Lock Step: No
    Status: DIMM is degraded


    want to extract Size: and Status: and need that in single line, like following



    Final output will look like following. I can use other language like python or perl but i wrote in bash so i need something in bash, i can do multiple for loop and play with variable to make it work but i need something easy or in-short single like like sed/awk. how can i achieve that in sed/awk?



    8192MB - Ok
    8192MB - OK
    8192MB - OK
    8192MB - DIMM is degraded








    share

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have bash script to collect all hardware info but following memory info piece is missing, so this is what i am trying to do.



      Following command give you status of DIMM memory module,



      [root@Linux ~]# hpasmcli -s 'show dimm'

      DIMM Configuration
      ------------------
      Processor #: 1
      Module #: 1
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: Ok

      Processor #: 1
      Module #: 12
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: Ok

      Processor #: 2
      Module #: 1
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: Ok

      Processor #: 2
      Module #: 12
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: DIMM is degraded


      want to extract Size: and Status: and need that in single line, like following



      Final output will look like following. I can use other language like python or perl but i wrote in bash so i need something in bash, i can do multiple for loop and play with variable to make it work but i need something easy or in-short single like like sed/awk. how can i achieve that in sed/awk?



      8192MB - Ok
      8192MB - OK
      8192MB - OK
      8192MB - DIMM is degraded








      share















      I have bash script to collect all hardware info but following memory info piece is missing, so this is what i am trying to do.



      Following command give you status of DIMM memory module,



      [root@Linux ~]# hpasmcli -s 'show dimm'

      DIMM Configuration
      ------------------
      Processor #: 1
      Module #: 1
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: Ok

      Processor #: 1
      Module #: 12
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: Ok

      Processor #: 2
      Module #: 1
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: Ok

      Processor #: 2
      Module #: 12
      Present: Yes
      Form Factor: 9h
      Memory Type: DDR3(18h)
      Size: 8192 MB
      Speed: 1333 MHz
      Supports Lock Step: No
      Configured for Lock Step: No
      Status: DIMM is degraded


      want to extract Size: and Status: and need that in single line, like following



      Final output will look like following. I can use other language like python or perl but i wrote in bash so i need something in bash, i can do multiple for loop and play with variable to make it work but i need something easy or in-short single like like sed/awk. how can i achieve that in sed/awk?



      8192MB - Ok
      8192MB - OK
      8192MB - OK
      8192MB - DIMM is degraded






      linux awk sed scripting regular-expression





      share














      share












      share



      share








      edited 4 mins ago









      Jeff Schaller

      34.4k951115




      34.4k951115










      asked 8 mins ago









      Satish

      61911130




      61911130




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Oh boy i think i did it :)



          [root@Linux ~]# hpasmcli -s 'show dimm' | egrep -e Size -e Status | awk -F: 'print $2' | sed 's/^[ t]*//' | awk 'NR%2printf "%s - ",$0;next;1'
          8192 MB - Ok
          8192 MB - Ok
          8192 MB - Ok
          8192 MB - DIMM is degraded


          Still i would like to know if anyother way we can do that, i am not going to answer my question i will wait for other folks to chime in.





          share




















            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f477793%2fextract-field-from-file-using-sed-or-awk%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Oh boy i think i did it :)



            [root@Linux ~]# hpasmcli -s 'show dimm' | egrep -e Size -e Status | awk -F: 'print $2' | sed 's/^[ t]*//' | awk 'NR%2printf "%s - ",$0;next;1'
            8192 MB - Ok
            8192 MB - Ok
            8192 MB - Ok
            8192 MB - DIMM is degraded


            Still i would like to know if anyother way we can do that, i am not going to answer my question i will wait for other folks to chime in.





            share
























              up vote
              0
              down vote













              Oh boy i think i did it :)



              [root@Linux ~]# hpasmcli -s 'show dimm' | egrep -e Size -e Status | awk -F: 'print $2' | sed 's/^[ t]*//' | awk 'NR%2printf "%s - ",$0;next;1'
              8192 MB - Ok
              8192 MB - Ok
              8192 MB - Ok
              8192 MB - DIMM is degraded


              Still i would like to know if anyother way we can do that, i am not going to answer my question i will wait for other folks to chime in.





              share






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Oh boy i think i did it :)



                [root@Linux ~]# hpasmcli -s 'show dimm' | egrep -e Size -e Status | awk -F: 'print $2' | sed 's/^[ t]*//' | awk 'NR%2printf "%s - ",$0;next;1'
                8192 MB - Ok
                8192 MB - Ok
                8192 MB - Ok
                8192 MB - DIMM is degraded


                Still i would like to know if anyother way we can do that, i am not going to answer my question i will wait for other folks to chime in.





                share












                Oh boy i think i did it :)



                [root@Linux ~]# hpasmcli -s 'show dimm' | egrep -e Size -e Status | awk -F: 'print $2' | sed 's/^[ t]*//' | awk 'NR%2printf "%s - ",$0;next;1'
                8192 MB - Ok
                8192 MB - Ok
                8192 MB - Ok
                8192 MB - DIMM is degraded


                Still i would like to know if anyother way we can do that, i am not going to answer my question i will wait for other folks to chime in.






                share











                share


                share










                answered 2 mins ago









                Satish

                61911130




                61911130



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477793%2fextract-field-from-file-using-sed-or-awk%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    The Forum (Inglewood, California)

                    Palaiologos