niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
how to execute new command with awk - if/then/else?
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
Author Message
martin
*nix forums beginner


Joined: 22 Feb 2005
Posts: 44

PostPosted: Tue Feb 08, 2005 11:26 am    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

thank you! you were right - those little changes got my code a'working
Smile
sorry the statements were tough to read, but i wanted to write it on a
single line just to make sure i was doing it correctly (new to this, ya
know ;^)
thanks again
martin
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Mon Feb 07, 2005 10:57 pm    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

martin wrote:
Quote:
ok, i tried to format code from your example into a single line string
of command statements...
the first time, i included the "> /dev/null/" portion, which i have no
idea what it means or causes to happen... here's the cut/paste of the
command exactly as i entered it... and, following that, the error
output from terminal.

./alan 3build6.alan >newtestoutput.txt ; if grep "No warnings"
newtestoutput.txt > /dev/null/ ; then ; ./arun 3build6 ; else ; printf
"bad compile, check file\n" ; end if ;

/dev/null/: Not a directory.

There's no "/" at the end of "/dev/null". See the original post.

Quote:
so i removed the dev/null/ portion and tried again, this time with a
different error.

./alan 3build6.alan >newtestoutput.txt; if grep "No warnings or errors
detected" newtestoutput.txt; then; ./arun 3build6; else; printf "bad
compile\n"; end if;

There's no space between "end" and "if" in the original post, but it
actually should be "fi" instead.

Please use newlines and other white-space when posting code segments -
it'll make spotting problems a lot easier.

Also, include the relevant section of the post you're responding to
since it's not always obvious.

Quote:
result: if: Expression Syntax.

note: the compile Was a success - the newtestoutput file Was
generated... but i don't believe that text string was compared in
either version before the error msg was triggered. i see what you
meant about simplifying - but in this case, i absolutly must have some
sort of string comparision to active the IF/ELSE statements.

Not from what you've posted so far.

Quote:
also - if you have time, please briefly tell me what dev/null/ is for.
(btw, my computer is mac osx 2.Cool

/dev/null is just a garbage can to send output to that you don't want to
see.

Ed.
Back to top
martin
*nix forums beginner


Joined: 22 Feb 2005
Posts: 44

PostPosted: Mon Feb 07, 2005 8:26 pm    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

ok, i tried to format code from your example into a single line string
of command statements...
the first time, i included the "> /dev/null/" portion, which i have no
idea what it means or causes to happen... here's the cut/paste of the
command exactly as i entered it... and, following that, the error
output from terminal.

../alan 3build6.alan >newtestoutput.txt ; if grep "No warnings"
newtestoutput.txt > /dev/null/ ; then ; ./arun 3build6 ; else ; printf
"bad compile, check file\n" ; end if ;

/dev/null/: Not a directory.

so i removed the dev/null/ portion and tried again, this time with a
different error.

../alan 3build6.alan >newtestoutput.txt; if grep "No warnings or errors
detected" newtestoutput.txt; then; ./arun 3build6; else; printf "bad
compile\n"; end if;

result: if: Expression Syntax.

note: the compile Was a success - the newtestoutput file Was
generated... but i don't believe that text string was compared in
either version before the error msg was triggered. i see what you
meant about simplifying - but in this case, i absolutly must have some
sort of string comparision to active the IF/ELSE statements.

also - if you have time, please briefly tell me what dev/null/ is for.
(btw, my computer is mac osx 2.Cool
thank you
martin
Back to top
martin
*nix forums beginner


Joined: 22 Feb 2005
Posts: 44

PostPosted: Mon Feb 07, 2005 12:59 pm    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

sorry about that... when i get home in this afternoon, i'll try it out
- and then i'll be able to cut/paste with my question again by
mid-afternoon.
thanks.
martin
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Mon Feb 07, 2005 12:01 pm    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

On Mon, 07 Feb 2005 at 12:32 GMT, martin wrote:
Quote:
Thanks for writing back (everyone). I'm so new to unix and terminal
that i haven't yet figured out how to do two things -(among about a
million other things Smile
one - type multi line commands into the terminal w/out terminal wanting
to process the first line after hitting return... or setting up a code
file for terminal to fetch to collect statements to run
and, two - how to just type the code you wrote above on one line using
";" to seperate each command.

since i think it'll be easier to put it all in one line (as i'm going
to have to have applescript send that line to terminal) could you
possibly re-type what you wrote above, and show me the format for doing
it all in one command line? when i tried last night, i kept getting
errors about how the ( ) were in the wrong place - (some examples i'd
seen used curly braces and ( ) and i was trying to follow that
syntax...)

i would really appreciate being able to see both side-by-side.
thanks so much!

First, please quote relevant material.

What do you want converted to a single line? As a rule of thumb,
where there was a new line, place a semi-colon. If that doesn't
work, show us exactly what you tried (cut and paste; do not
retype) along with the exact error message, if any.

Note that braces { } need to be separated by spaces, and the
closing brace preceded by a semi-colon is it's all on one line:

{ echo A; read B; }


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Back to top
martin
*nix forums beginner


Joined: 22 Feb 2005
Posts: 44

PostPosted: Mon Feb 07, 2005 11:32 am    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

Thanks for writing back (everyone). I'm so new to unix and terminal
that i haven't yet figured out how to do two things -(among about a
million other things Smile
one - type multi line commands into the terminal w/out terminal wanting
to process the first line after hitting return... or setting up a code
file for terminal to fetch to collect statements to run
and, two - how to just type the code you wrote above on one line using
";" to seperate each command.

since i think it'll be easier to put it all in one line (as i'm going
to have to have applescript send that line to terminal) could you
possibly re-type what you wrote above, and show me the format for doing
it all in one command line? when i tried last night, i kept getting
errors about how the ( ) were in the wrong place - (some examples i'd
seen used curly braces and ( ) and i was trying to follow that
syntax...)

i would really appreciate being able to see both side-by-side.
thanks so much!
martin
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Mon Feb 07, 2005 3:36 am    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

martin wrote:
Quote:
i'm trying to figure out the syntax for building an awk statement that
will check the output of text in a file generated after attempting to
compile a source code file. i'm new to unix and don't know how to
issue statements to terminal if they're embedded inside an if/then
control statement.

./alan 3build6.alan > alan_output.txt ; awk (if ~/No warnings or errors
detected/ printf ./arun 3build6); else print "compile wasn't a success"

Much as I like awk, it seems inappropriate for what you appear to be
trying to do. Try this:

../alan 3build6.alan > alan_output.txt
if grep "No warnings or errors detected" alan_output.txt >/dev/null
then
./arun 3build6
else
printf "compile wasn't a success\n"
endif

If the command "allan" exits with a failure code when it issues a
warning (debatable if it should) or error (almost certainly should),
then you could simplify the above to:

if ./alan 3build6.alan > alan_output.txt
then
./arun 3build6
else
printf "compile wasn't a success\n"
endif

Regards,

Ed.
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Mon Feb 07, 2005 12:43 am    Post subject: Re: how to execute new command with awk - if/then/else? Reply with quote

On Mon, 07 Feb 2005 at 01:19 GMT, martin wrote:
Quote:
i'm trying to figure out the syntax for building an awk statement that
will check the output of text in a file generated after attempting to
compile a source code file. i'm new to unix and don't know how to
issue statements to terminal if they're embedded inside an if/then
control statement.

./alan 3build6.alan > alan_output.txt ; awk (if ~/No warnings or errors
detected/ printf ./arun 3build6); else print "compile wasn't a success"

i'm trying to tell terminal to run the executable file by issuing a
command "./arun 3build6" if the string "No warnings or errors detected"
exists in the alan_output.txt file. once i understand that - i'd also
like to add some other more sophisticated commands in the "else"
portion of the code... but for now, i was just using the "compile
wasn't a success" as a way of checking the code's functionality.

i found on some of the awk pages that some examples used the printf
command - but i don't know what that does. i do now want - or do not
need for: "./arun 3build6" to be printed to the terminal screen unless
it will be printed into a command line, with the equivilant of hitting
the return button to execute it.

any wisdom would really be appreciated. Smile

I don't know just what you are trying to do, but perhaps this will
help.

To run one command when a previous command exits successfully, and
another when it fails:

if command
then
: successful command here
else
: unsuccessful command here
fi

I you need to check for the existence of something in the first
command's output, use the success or failure of grep:

command | ## tee alan_output.txt | ## uncomment to also save output in a file
if grep "No warnings or errors detected" >/dev/null
then
: successful command here
else
: unsuccessful command here
fi


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Back to top
martin
*nix forums beginner


Joined: 22 Feb 2005
Posts: 44

PostPosted: Mon Feb 07, 2005 12:19 am    Post subject: how to execute new command with awk - if/then/else? Reply with quote

i'm trying to figure out the syntax for building an awk statement that
will check the output of text in a file generated after attempting to
compile a source code file. i'm new to unix and don't know how to
issue statements to terminal if they're embedded inside an if/then
control statement.

../alan 3build6.alan > alan_output.txt ; awk (if ~/No warnings or errors
detected/ printf ./arun 3build6); else print "compile wasn't a success"

i'm trying to tell terminal to run the executable file by issuing a
command "./arun 3build6" if the string "No warnings or errors detected"
exists in the alan_output.txt file. once i understand that - i'd also
like to add some other more sophisticated commands in the "else"
portion of the code... but for now, i was just using the "compile
wasn't a success" as a way of checking the code's functionality.

i found on some of the awk pages that some examples used the printf
command - but i don't know what that does. i do now want - or do not
need for: "./arun 3build6" to be printed to the terminal screen unless
it will be printed into a command line, with the equivilant of hitting
the return button to execute it.

any wisdom would really be appreciated. :)

thank you.
martin
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 10:19 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Solaris dd command problem prak Solaris 0 Fri Jul 21, 2006 5:43 am
No new posts Solaris dd command problem prak Solaris 0 Fri Jul 21, 2006 5:43 am
No new posts Solaris dd command problem prak Solaris 4 Fri Jul 21, 2006 5:43 am
No new posts Why nohup & doesn't work? ankyhe@gmail.com Solaris 2 Wed Jul 19, 2006 12:13 pm
No new posts Bug#378859: ITP: pypar2 -- graphical frontend for the par... Piotr Ozarowski devel 1 Wed Jul 19, 2006 12:00 pm

Loans | Debt Consolidation | Mobile Phone | Mobile Phones | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2059s ][ Queries: 20 (0.0984s) ][ GZIP on - Debug on ]