LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   C shell script issues (https://www.linuxquestions.org/questions/linux-software-2/c-shell-script-issues-105290/)

daveb93 10-17-2003 04:32 PM

C shell script issues
 
Hi,

I'm running RedHat 9.0. I have a C shell script that calls an awk program:
gawk -f awkProg temp.txt

temp.txt has (among others) the following lines:
Max Value = 12343.3434
blah
Max Value = 23423.234
blah

my awk program has the following BEGIN statement:
BEGIN { FS = " " }
/^Max/
{
scaleArray[i++] = $4
}

END
{
here, I just find the max value in scaleArray[]
}

so there are no 'print's in this right? right. But, when I execute
'gawk -f awkProg temp.txt'
I get all the matches printed out to Standard Out

Max Value = 12343.3434
Max Value = 23423.234
...

and so on. How did this happen!?!?!?

AND here's a second question.
In my C shell script I'm running a program which generates the above 'Max Value' value. After the program generates all the 'Max Value''s it goes on to do 'other' stuff and all output is redirected to temp.txt. Can I use grep or awk from within the shell script to stop this program (by using Ctrl-C) to prevent it from doing it's 'other' stuff?? This would speed up the script significantly.

Cheers
-Dave:Pengy:

jailbait 10-17-2003 06:35 PM

"How did this happen!?!?!?"

By any chance do you have a trap command in the script which sets the debug option?


___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites

jailbait 10-17-2003 06:39 PM

"Can I use grep or awk from within the shell script to stop this program (by using Ctrl-C) to prevent it from doing it's 'other' stuff?? This would speed up the script significantly. "

Possibly. Another possibility is the have the subprogram direct its output to /dev/null instead of temp.txt. Or you could write a second version of the subprogram which does not include the "other stuff"


___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites

ToniT 10-17-2003 08:19 PM

Probably the easiest way is to
Code:

sed '/When i see this line I end the reading of input and stop/Q'
About the first question, you don't have the hole script there so I can't reproduce
the problem as is, but one thing is your spurious use of newlines (probably in places
where they are not allowed)
case 1:
Code:

/foo/
{
print "I print something for every line";
}

In fact that code prints that string for every line + it prints foo as is (empy rule is implicit print)

case 2:
Code:

/foo/ {
print "What happens now?";
}

And what now happens is that when foo is encountered, the "What happens now?" is printed, other lines are ignored.


All times are GMT -5. The time now is 12:38 PM.