Re: Shell scripting issue (46 Views)
Reply
Regular Advisor
Dewa Negara_4
Posts: 194
Registered: ‎04-14-2003
Message 1 of 10 (46 Views)
Accepted Solution

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
Please use plain text.
Esteemed Contributor
Vibhor Kumar Agarwal
Posts: 787
Registered: ‎04-05-2005
Message 2 of 10 (46 Views)

Re: Shell scripting issue

Try something like:

sed -e '/BEGIN M400#4,/END M400#4/p'
Vibhor Kumar Agarwal
Please use plain text.
Honored Contributor
Leif Halvarsson_2
Posts: 6,682
Registered: ‎01-09-2002
Message 3 of 10 (46 Views)

Re: Shell scripting issue

Hi,

There is several ways to do this,
cat | awk ' $1 !~ /###/ { print $0 }'
Please use plain text.
Regular Advisor
Dewa Negara_4
Posts: 194
Registered: ‎04-14-2003
Message 4 of 10 (46 Views)

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
Please use plain text.
Regular Advisor
Dewa Negara_4
Posts: 194
Registered: ‎04-14-2003
Message 5 of 10 (46 Views)

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
Please use plain text.
Esteemed Contributor
Vibhor Kumar Agarwal
Posts: 787
Registered: ‎04-05-2005
Message 6 of 10 (46 Views)

Re: Shell scripting issue

Okay,

Just a small modification.

sed -n '/BEGIN M400#4/,/END M400#4/p'
Vibhor Kumar Agarwal
Please use plain text.
Esteemed Contributor
Alessandro Pilati
Posts: 355
Registered: ‎06-30-2005
Message 7 of 10 (46 Views)

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
Please use plain text.
Honored Contributor
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 8 of 10 (46 Views)

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!
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 9 of 10 (46 Views)

Re: Shell scripting issue

grep \/var\/ fileA
"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
Regular Advisor
Dewa Negara_4
Posts: 194
Registered: ‎04-14-2003
Message 10 of 10 (46 Views)

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
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation