New to forums and had a quick one.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New to forums and had a quick one.
# 1  
Old 10-20-2008
New to forums and had a quick one.

I am trying to use grep or awk to search for a specific number in a file. For eg.

grep -i "Tag: 140" filename.

The above command also lists other Tag: 140 like below.

Tag: 1409970
Tag: 1409969
Tag: 1409749
Tag: 1409968
Tag: 1409750
Tag: 140
Tag: 1409751
Tag: 1409752
Tag: 1409746
Tag: 1409966

I need only a specific number and not all numbers starting in 140.

Thanks so much.
# 2  
Old 10-20-2008
Use a better regexp to anchor the expression...
Code:
grep '^Tag: 140$' file

assuming that the file has a list of "Tag: Value" pairs and nothing else in it.
# 3  
Old 10-20-2008
Thanks shamrock , i appreciate it.

Yes the file has other information and extra lines and they keep changing , but all i need is to grep for a three digit Tag: number starting with 140. Instaed of listing all lines starting with 140

Tag: 14099 Authority: 87 Status: 0x00 Region: 80
VSR header time: 10-14-2008 13:34:03 SeqNum: 56
Tag: 1406 Authority: 254 Status: 0x00 Region: 70
VSR header time: 10-14-2008 13:37:13 SeqNum: 57
Tag: 14095 Authority: 67 Status: 0x00 Region: 60
VSR header time: 10-14-2008 13:38:38 SeqNum: 58
Tag: 140 Authority: 88 Status: 0x00 Region: 50
VSR header time: 10-14-2008 13:39:15 SeqNum: 59
# 4  
Old 10-20-2008
In your example, you just want to return the last row that starts with Tag:? If so, just include the trailing space in your grep.
# 5  
Old 10-20-2008
Hammer & Screwdriver try the following

based on the example having more stuff after the 140...

Code:
grep "^Tag: 140 " workfile

# 6  
Old 10-21-2008
That worked. I am glad i found this forum. Thanks all again.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

I am not able to register in the forums

Hi, I am from India. I am not able to register in this forum. Can you kindly help me to register and post. Thanks Gautam (1 Reply)
Discussion started by: Unregistered
1 Replies

2. Solaris

Forums...

Hi all, Thanks for any posts and for reading. I was wondering if any of guys know of a open source style forum that I could get hold of that would be easily run on solaris. I know you can use many different varities of PHP/mysql/apache but is there anything a bit more simplier that could be... (0 Replies)
Discussion started by: B14speedfreak
0 Replies

3. What is on Your Mind?

other forums..

anyone here a member of any other NON computer related forums? i am very much into cars, and i own a 1986.5 toyota supra :D , so i am a member of a few mkiii (third generation supra) related forums: supraforums.com supramania.com mkiiitech.com (2 Replies)
Discussion started by: norsk hedensk
2 Replies
Login or Register to Ask a Question