LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-17-2003, 05:32 PM   #1
daveb93
LQ Newbie
 
Registered: Sep 2003
Location: Worcester, MA
Posts: 8

Rep: Reputation: 0
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
 
Old 10-17-2003, 07:35 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,789

Rep: Reputation: 292Reputation: 292Reputation: 292
"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
 
Old 10-17-2003, 07:39 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,789

Rep: Reputation: 292Reputation: 292Reputation: 292
"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
 
Old 10-17-2003, 09:19 PM   #4
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 07:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 04:00 PM


All times are GMT -5. The time now is 01:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration