1 Reply Latest reply: Oct 16, 2012 7:46 PM by Catch_22 RSS

    storing part of the file content into a variable.

    Gor_Mahia
      All,
      I have a log file containing lots of data now i want to extract all text between block below(only names) without the title/end pattern but only names,
      ++++START++++
      SCOTT TIGER
      HENRY PAUL
      JARED TEXAS
      BILL G. OWENS
      ++++END++++

      the names i want to return and store in a variable in my korn-shell code.
      Any help on this please?

      regards,
        • 1. Re: storing part of the file content into a variable.
          Catch_22
          Perhaps the following is not the most sophisticated solution, but probably easy to understand:

          <pre>
          $ var=$(sed -n '/++++START++++/,/++++END++++/p' your_logfile | head -n -1 | tail -n +2)

          $ echo "$var"
          SCOTT TIGER
          HENRY PAUL
          JARED TEXAS
          BILL G. OWENS
          </pre>

          Note that you have to echo "$var" in double quotes in order for echo to print newlines.