School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,015 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,073 people online right now. Registration is fast and FREE... Join Now!




Bourne shell scripting help?

 

Bourne shell scripting help?

mattpd

30 Oct, 2009 - 10:57 AM
Post #1

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 21

I have a text file, and I need to write a script to search the text file for the users input. If the input already exists, print error. Otherwise add input to the text file.

My question is, can you set a 'flag' when you use grep to search the file for the input? I know how to do the rest... So if grep finds something, error, else add to txt file.

User is offlineProfile CardPM
+Quote Post


brds

RE: Bourne Shell Scripting Help?

30 Oct, 2009 - 04:48 PM
Post #2

D.I.C Regular
***

Joined: 22 Oct, 2008
Posts: 442



Thanked: 36 times
My Contributions
You mean like capture the out of grep?
CODE

$myvar=`grep "expr" file`

User is offlineProfile CardPM
+Quote Post

baavgai

RE: Bourne Shell Scripting Help?

30 Oct, 2009 - 05:05 PM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,348



Thanked: 411 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Your grep should have a '-c' flag. This gets you a count of matches. So a zero means no matches. You should be able to take if from there.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:33AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month