1752439 Members
5596 Online
108788 Solutions
New Discussion юеВ

Shell scripting issue

 
SOLVED
Go to solution
Dewa Negara_4
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 9
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Shell scripting issue

Try something like:

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

Re: Shell scripting issue

Hi,

There is several ways to do this,
cat | awk ' $1 !~ /###/ { print $0 }'
Dewa Negara_4
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
Dewa Negara_4
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
Vibhor Kumar Agarwal
Esteemed Contributor
Solution

Re: Shell scripting issue

Okay,

Just a small modification.

sed -n '/BEGIN M400#4/,/END M400#4/p'
Vibhor Kumar Agarwal
Alessandro Pilati
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
Muthukumar_5
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!
TwoProc
Honored Contributor

Re: Shell scripting issue

grep \/var\/ fileA
We are the people our parents warned us about --Jimmy Buffett
Dewa Negara_4
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