Computing.Net > Forums > Unix > if statement

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

if statement

Reply to Message Icon

Name: bhben
Date: January 20, 2005 at 08:06:39 Pacific
OS: Windows XP
CPU/Ram: P4, 512MB
Comment:

I have a file that consists of a blank line, then either Y or N and then another blank line. I want to take this into an if statement saying if the file contains a Y then do this else do that. I've tried a few ways but i think i am getting my code a bit wrong. what's the best way to do this?



Sponsored Link
Ads by Google

Response Number 1
Name: vgersh99
Date: January 20, 2005 at 08:24:24 Pacific
Reply:

if [ "$( sed -e '/^$/d' file)" = "Y" ]; then
echo "do this"
else
echo "do that"
fi;


0

Response Number 2
Name: WilliamRobertson
Date: February 26, 2005 at 12:08:30 Pacific
Reply:

Or just

if grep Y filename 2>&1 >/dev/null
then
echo "Do this"
else
echo "Do that"
fi

Some grep implementations have a -s (silent) option or similar, which lets you do without the "2>&1 >/dev/null".


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


ftp script issue Unix Find command output ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: if statement

While read is ignoring if statement www.computing.net/answers/unix/while-read-is-ignoring-if-statement/7435.html

If statement in unix www.computing.net/answers/unix/if-statement-in-unix/7097.html

IF statements Comparing variables www.computing.net/answers/unix/if-statements-comparing-variables/6628.html