BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Shell scripting issue

SOLVED
Go to Solution
Regular Advisor

Shell scripting issue

Hi All,

I have an issue on a shell scripting. I have a regular file called fileA below :

##### BEGIN M400#4 #####
/var/opt/secu/log/console
/var/spool/sockets/pwgr
/var/opt/dce/rpc/local/s-0
/var/opt/dce/rpc/local/s-3
/var/spool/cron/tmp
##### END M400#4 #####

How can I trigger the file using a shell script, so the result will be all lines between "BEGIN M400#4" and "END M400#4".

So the result should be :
/var/opt/secu/log/console
/var/spool/sockets/pwgr
/var/opt/dce/rpc/local/s-0
/var/opt/dce/rpc/local/s-3
/var/spool/cron/tmp

Pls help. High score will be given.

Thanks for your help in advance.

Best Regards,
Dewa
Santos
9 REPLIES
Esteemed Contributor

Re: Shell scripting issue

Try something like:

sed -e '/BEGIN M400#4,/END M400#4/p'
Vibhor Kumar Agarwal
Honored Contributor

Re: Shell scripting issue

Hi,

There is several ways to do this,
cat | awk ' $1 !~ /###/ { print $0 }'
Regular Advisor

Re: Shell scripting issue

Thanks alot for your help.

Hi Vibhor,

I got an error message when run your script :

[root@sihp8039:/home/ap1030]
# sed -e '/BEGIN M400#4,/END M400#4/p'
sed: /BEGIN M400#4,/END M400#4/p is not a recognized function.



Hi Leif,

How can we state on the script with "BEGIN M400#4" and "END M400#4"? How the command will be?

Best Regards,
Dewa
Santos
Regular Advisor

Re: Shell scripting issue

Hi Vibhor,

I got this error when I run as your advise.

[root@sihp8039:/home/ap1030]
# sed -e '/BEGIN M400#4/END M400#4/p' fileA
sed: /BEGIN M400#4/END M400#4/p is not a recognized function.

Thanks.
Dewa

Santos
Esteemed Contributor

Re: Shell scripting issue

Okay,

Just a small modification.

sed -n '/BEGIN M400#4/,/END M400#4/p'
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Shell scripting issue

Dewa,
another simple way:

grep -v "^###" fileA

Rgds,
Alex
if you don't try, you'll never know if you are able to
Honored Contributor

Re: Shell scripting issue

awk '$0 !~ "##"{ print; }'

or

egrep -v 'BEGIN M400|END M400'

hth.
Easy to suggest when don't know about the problem!
Honored Contributor

Re: Shell scripting issue

grep \/var\/ fileA
We are the people our parents warned us about --Jimmy Buffett
Highlighted
Regular Advisor

Re: Shell scripting issue

Hi All,

I got the answer.

Thank you very much for your help.

Have a nice day.

Best Regards,
Dewa
Santos