1753511 Members
5356 Online
108795 Solutions
New Discussion юеВ

Problem on scripting.

 
SOLVED
Go to solution
Kenny Chau
Trusted Contributor

Problem on scripting.

I am writing a script to capture something from a DB with the DB command "promon" which will call a menu. In fact, I can capture the data that I want but it also displays the menu together with the data. So I want to know how to make the menu disappear but only appear the output.
My script is something like below:

FunctionA ()
{
{
promon DB1 <<-EOF | grep "data"
1
2
q
q
EOF
} > file1
}

And the output is something like this:

Menu:
1. xxxx
2. xxxx
3. xxxx

q. exit

Choice:


I had tried to use "1> /dev/null" in some places but failed to get the data.

Hope you guys can help me.

Thanks very much.
Kenny
7 REPLIES 7
Praveen Bezawada
Respected Contributor

Re: Problem on scripting.

Hi
Why don't you grep out the MENU from the file after it has got generated, like

grep -v "MENU" file.lst > file.lst.tmp
mv file.lst.tmp file.lst

...BPK...
Kenny Chau
Trusted Contributor

Re: Problem on scripting.

Thanks for your response, BPK.
I had tried to generate the whole things (menu and data) to a file and then grep the necessary data but still failed.

I had modified the script to:

FunctionA ()
{
{
promon DB1 <<-EOF
1
2
q
q
EOF
} > file1
}
grep "data" file1

However, it still shows the menu in the screen together with the "data".

Actually I want to make the menu not showing in the screen and only shows the "data".
Kenny
Praveen Bezawada
Respected Contributor

Re: Problem on scripting.

HI
Use grep -v "MENU" to remove the menu., redirect in into a file...
Kenny Chau
Trusted Contributor

Re: Problem on scripting.

Thanks for your quick response, BPK.
Sorry that I did not state myself clear. Actually I want to make the menu NOT showing on the screen but only show the "data". I had tried your method but it still shows the menu on the screen even I tried to add "grep -v MENU". Do you have any other methods that can tell me??

Thanks.
Kenny
Klaus Crusius
Trusted Contributor
Solution

Re: Problem on scripting.

Hi Kenny,

it is possible, that the promon program outputs the menu to the STDERR file descriptor (2) and not to the STDOUT (1). To discard the output on STDERR redirect in this way:

...
} 2>/dev/null 1>file

I assume (because of the grep "data") that all output lines you want to see contain the text "data" somewhere.

You could make the selectivity more accurate, if you knew, that the text appears alway at the beginning of the line (grep "^data") or at the end of the line (grep "data$").
Maybe you don't need the grep at all.

If the output cannot be separated from the menu in the described way, then a small awk script could help:

...
} |
awk '/^Choice:/ { xxx=1 }
xxx
'

Regards, Klaus
There is a live before death!
Klaus Crusius
Trusted Contributor

Re: Problem on scripting.


Correction:

awk '/^Choice:/ { xxx=1; next }
.....

Klaus
There is a live before death!
Kenny Chau
Trusted Contributor

Re: Problem on scripting.

Thanks Klaus.
Actually your first answer had solved my problem.
Kenny