This discussion is archived
1 Reply Latest reply: Oct 16, 2012 5:46 PM by Dude! RSS

storing part of the file content into a variable.

Gor_Mahia Explorer
Currently Being Moderated
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.
    Dude! Guru
    Currently Being Moderated
    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points