tags:

views:

53

answers:

3

I have a txt file that looks something like this

-----------------------------------
           RUNNING PROCESSES
-----------------------------------

ftpd
kswapd
init
etc..

---------------------------------
          HOSTNAME
--------------------------------

mypc.local.com

With sed I want to just get one section of this file. So just the RUNNING PROCESSES section, however I seem to be failing to get my regexp right to do so.

I got this far

sed -n '/^-./,/RUNNING PROCESSES/, /[[:space::]]/p' linux.txt | more

however it keeps complaining about

-e expression #1, char 26: unknown commmand `,'

Can anybody help??

+2  A: 

Did you mean:

sed -n '/RUNNING PROCESSES/,/HOSTNAME/p' linux.txt | 
  sed -e '/^[- ]/d' -e '/^$/d'
msw
I just want the 'Running Processes' section...
Tony
A: 

I would probably prefer to use awk for that:

awk '/RUNNING PROCESSES/ {s=2}
     /^---/              {s=s-1}
                         {if(s>0){print}}' linux.txt

That awk will give you:

           RUNNING PROCESSES
-----------------------------------

ftpd
kswapd
init
etc..

You can then pipe that through sed '/^$/d' to filter out the blank lines.

paxdiablo
A: 

Here is another variable of the answer accepted, but not extra call to another sed process

sed -n '/RUNNING PROCESSES/,/HOSTNAME/{s/RUNN.*\|HOSTNAME//;s/--*//;/^$/!p}' file
ghostdog74