grep, cgrep or something close


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep, cgrep or something close
# 1  
Old 03-05-2007
grep, cgrep or something close

Hi,

New to this forum. Nice forum and very helpful.

Quick question. I'm trying to grep a list of numbers from single digit to 3-digit. For example, I have a pool of numbers that contain two specific numbers, 17 and 177. I would like to grep for 17 but not get 177. When using grep, I also get 177 unless I grep for "17 ", adding an additional space. Is there a way I can exclude that extra 7 but also include it if I grep for the actual number 177? Would this be what delimiters are?

Thanks
dj
# 2  
Old 03-05-2007
Quote:
Originally Posted by dejit
Hi,

New to this forum. Nice forum and very helpful.

Quick question. I'm trying to grep a list of numbers from single digit to 3-digit. For example, I have a pool of numbers that contain two specific numbers, 17 and 177. I would like to grep for 17 but not get 177. When using grep, I also get 177 unless I grep for "17 ", adding an additional space. Is there a way I can exclude that extra 7 but also include it if I grep for the actual number 177? Would this be what delimiters are?

Thanks
dj
If those numbers are within a file, 1 number on each line:

grep "^[0-9][0-9]$" file
# 3  
Old 03-05-2007
Thanks for the response. I may be missing your explanation. How about this:

Here's a file with only two lines:

This line has the number 17 in it. I would like to grep only it.
This line has the number 177 in it. I would like to exclude it.

Here's the command I'm using:
grep "17" <filename>

This returns both line one and two, when I'm only wanting line one. Is this possible?
Sorry if you answered this and I'm simply not getting it.

Thanks so much.
dj
# 4  
Old 03-06-2007
Code:
grep "[^0-9]17[^0-9]" file

or
Code:
grep -w "17" file

# 5  
Old 03-06-2007
Excellent. This worked. Thanks!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Please close this account

Hi admins and moderators! I would request you to please close this account as I will not be using it ever. Thank you all. Ravi Singh (1 Reply)
Discussion started by: Ravi Singh
1 Replies

2. Programming

Close browser

I just would like to have a javascript function ( for user logout ) which can close the browser that the user run this function , for example , if the user is using IE to click this function , then close ALL IE browser , is it possible ? if it can not be make , could the function close ALL opened... (2 Replies)
Discussion started by: ust3
2 Replies

3. Post Here to Contact Site Administrators and Moderators

Why close my ask?

Hello, Why close my ask "How to implement a semaphore with pedestrian pushbutton" i'm autodidact, so i don't understand why you dedice close it. I put the ask about Java (the language what i'm learning in spanish forum becouse my english is not good) but some body told me that this is the... (1 Reply)
Discussion started by: NewBe
1 Replies

4. Programming

when parent process close, how to close the child?

can someone provide an example, where if the parent process quits for any reason, then the child process will also close? (3 Replies)
Discussion started by: omega666
3 Replies

5. Post Here to Contact Site Administrators and Moderators

How to close account

Hi, I want to close my account and cannot find any relevant links in the user control panel or account preferences. Can someone point me in the right direction, or a moderator/admin close this account? Thanks. (1 Reply)
Discussion started by: glen.barber
1 Replies

6. Post Here to Contact Site Administrators and Moderators

How to close a topic?

No wonder that so few topics are closed. Looking for the fourth time as I do not find! (4 Replies)
Discussion started by: popescu1954
4 Replies

7. Forum Support Area for Unregistered Users & Account Problems

How to close a post

Hi, Pls let me know how i can close a thread if i already find answer to my question. Thanks, Am (1 Reply)
Discussion started by: am_yadav
1 Replies

8. UNIX and Linux Applications

any way to close socket

I have written a socker program. I have executed that program many times without closing the socket. So I want to find which all sockets binded with which file descriptor. Is there any way to close those socket, which have been opened in that program's execution. please help me!.. (3 Replies)
Discussion started by: pa.chidhambaram
3 Replies

9. Shell Programming and Scripting

cgrep for the most recent 15min output

I have a history file that recieves all sorts of messages 24 hours a day. I have a script that retreives various messages in the history file. There is an one multi line output that is sent to the history file that comes in every 15 minutes. How do I cgrep for the most recent 15 minute output in... (5 Replies)
Discussion started by: jojojmac5
5 Replies

10. Post Here to Contact Site Administrators and Moderators

How to close a thread

Hi Dumb question I know but I am new to this forum and have looked every where on this site but can not find "How to close" a thread I have posted.... Please advise on the procedures. Thanks Andrek (3 Replies)
Discussion started by: Andrek
3 Replies
Login or Register to Ask a Question