LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2010, 06:10 AM   #1
yanivmomo
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
Question need help with wildcards


I have a file within there is this sentence: "title dos". how could i know with if condition that this sentence exist in the file and it exactly as it should be. I dont have a problem if the line will end with whitespaces or tabs(this may happen if someone didn't write it right("title dos ").what i mean is how could i know the line is right and doesnt end with a letter that someone wrote in mistake
(for example:"title dos h"). I will be so glad if someone could help and send the exact answer.i know how to find the sentence(egrep 'title dos([[:space:]]*)?$' filename) but i dont know how to put it in an if condition(as part of a script)
 
Old 05-24-2010, 06:13 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello and welcome to LinuxQuestions,

Assign the command to a variable and then test the variable with your if statement:
Code:
variable=`egrep 'title dos([[:space:]]*)?$' filename`
I'll leave the if statement to you since this sounds a bit like homework to me

Kind regards,

Eric
 
Old 05-24-2010, 07:25 AM   #3
yanivmomo
LQ Newbie
 
Registered: May 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Question still have a problem

the problem is that i tried it with a variable but still dont know to what should i compare it
 
Old 05-24-2010, 07:32 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

The variable will hold the result of the command you put between `` so you should compare to that's what you test against. If it's true then do something, if it's not true then do nothing.

Have a look at Bash Beginners Guide more in particular Chapter 7.

Kind regards,

Eric
 
Old 05-24-2010, 07:37 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Or if you want to be a little tricky you can use the '-q' switch and then just test the return of success or failure
 
  


Reply



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
need help with wildcards liorpana Programming 2 05-12-2010 08:45 AM
using wildcards nadroj Linux - General 5 01-28-2007 08:39 PM
CLI wildcards ShakyJake Linux - Newbie 4 02-28-2005 03:42 PM
Wildcards dazdaz Linux - Newbie 3 01-23-2005 05:33 AM
Wildcards in kernel Squall Linux - General 1 04-20-2004 05:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:59 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
Open Source Consulting | Domain Registration