Grep wildcards


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep wildcards
# 1  
Old 06-11-2012
Grep wildcards

Hi all
I want to search for number in file presented with wildcard as shown below.
cat file.txt
Code:
1405
1623[0-5]
1415[0-9][0-9]
.......
.......

How to search for the number 141526 for example?
If the number exist print "Number 141526 exist" if no, print "The number not exist"

Thank you in advance.

Last edited by Scrutinizer; 06-11-2012 at 08:20 AM.. Reason: code tags
# 2  
Old 06-11-2012
Try:
Code:
number=141526
if echo "$number" | grep -qf file.txt; then
  echo "Number $number exists"
else
  echo "The number does not exist"
fi


Last edited by Scrutinizer; 06-11-2012 at 08:46 AM..
# 3  
Old 06-11-2012
Try:
Code:
echo 141526 | grep -f file.txt > /dev/null && echo "Number 141526 exists" || echo "Number 141526 does not exist"

# 4  
Old 06-11-2012
Thank you for the quick answers. Both options work perfectly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep multiple patterns that contain wildcards

job_count=`grep -e "The job called .* has finished | The job called .* is running" logfile.txt | wc -l` Any idea how to count those 2 patterns so i have a total count of the finished and running jobs from the log file? If i do either of the patterns its works okay but adding them together... (8 Replies)
Discussion started by: finn
8 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Wildcards used in find, ls and grep commands

Platforms : Solaris 10 and RHEL 5.6 I always get double quotes , single quotes and asteriks mixed up for find, ls and grep commands. The below commands retrieve the correct results. But , unders stress , I get all these mixed up :mad: .So, i wanted to get a clear picture. Please check if... (7 Replies)
Discussion started by: John K
7 Replies

3. Shell Programming and Scripting

Perl - grep issue in filenames with wildcards

Hi I have 2 directories t1 and t2 with some files in it. I have to see whether the files present in t1 is also there in t2 or not. Currently, both the directories contain the same files as shown below: $ABC.TXT def.txt Now, when I run the below script, it tells def.txt is found,... (5 Replies)
Discussion started by: guruprasadpr
5 Replies

4. UNIX for Advanced & Expert Users

Wildcards

These 2 websites do a GREAT job of explaining different types of wildcards. I learned about the categories of characters which I never knew about at all. GNU/Linux Command-Line Tools Guide - Wildcards GREP (1 Reply)
Discussion started by: cokedude
1 Replies

5. UNIX for Dummies Questions & Answers

wildcards NOT

Hi All Please excuse another straightforward question. When creating a tar archive from a directory I am attempting to use wildcards to eliminate certain filetypes (otherwise the archive gets too large). So I am looking for something along these lines. tar -cf archive.tar * <minus all *.rst... (5 Replies)
Discussion started by: C3000
5 Replies

6. UNIX for Dummies Questions & Answers

ls with wildcards

ok, I'm trying to write a script file that lists files with specific elements in the name into a txt file, it looks like this ls s*.dat > file_names.txt can't figure out whats wrong with that line, any ideas? thanks in advance (10 Replies)
Discussion started by: benu302000
10 Replies

7. UNIX for Dummies Questions & Answers

wildcards

when writing a shell script (bourne) and using a unix command like 'ls' is there anything special you need to do to use a wildcard (like *)? (3 Replies)
Discussion started by: benu302000
3 Replies

8. UNIX for Dummies Questions & Answers

grep and wildcards

Hi guys, a small problem today, I'm grepping a log file containing lines like this below: Mar 09 16:04:00 blabla Mar 09 16:04:02 blabla Mar 09 16:04:05 blabla Mar 09 16:04:15 blabla Mar 09 16:05:06 blabla Mar 09 16:05:23 blabla Mar 09 16:05:25 blabla ... in this file I'm grepping... (5 Replies)
Discussion started by: Lomic
5 Replies

9. UNIX for Dummies Questions & Answers

Wildcards In UNIX

on my SCO UNIX wild cards are not displaying wanted result. Why like that . I think that i was not using proper command . what are there . how can i use the wildcards in UNIX. (7 Replies)
Discussion started by: smdakram
7 Replies

10. UNIX for Dummies Questions & Answers

Wildcards in VI

I'm trying to delete lines from a large text file using VI. Every line that I am wanting to delete start with 'S' - all others do not. (A list of users) I've tried using * but doesn't seem to like it...any ideas... Doesn't have to be VI - but I'm better with VI than sed/awk. (8 Replies)
Discussion started by: peter.herlihy
8 Replies
Login or Register to Ask a Question