Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Check for entry of specific pattern Post 302836027 by TAPE on Tuesday 23rd of July 2013 11:36:22 AM
Old 07-23-2013
Check for entry of specific pattern

Hey Guys and Gals,

I am having trouble with what I thought shouldn't be hard..

In a script I am working on there is a need to enter a MAC address.

MAC addresses are formatted ;
XX:XX:XX:XX:XX:XX

where X can be 0-9, a-f or A-F


So in the sample script the query is something along the lines of ;
(realize the syntax is wrong but hope you get what I am getting at Smilie )

Code:
 
if [[ $INPUT == [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F] ]] ; then echo "Happy Puppy :) " 
else 
echo "Sad Puppy :( "
fi


Obviously the above is not working, but what would be the best way to check whether the variable is indeed following the desired pattern ?
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Not able to check for entry within file

Hi I am basically checking if a required entry exists within a file. In the code below I am fetching all directories of the format rel1, rela, rel3..etc..The same entries also exist in the sample log file. I want to check if entry in file1 exists within file2 but it is failing. Can you please... (4 Replies)
Discussion started by: swasid
4 Replies

2. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

3. Shell Programming and Scripting

Notification of the modification of a specific entry in a file

I need to get notification via email when the line containing a pattern is changed in a file. Not during the time any changes to file occurs. Ie if we reset a user password say example, demouser the hash in the line containing the word demouser in the file /etc/group changes. So when this change... (1 Reply)
Discussion started by: anil510
1 Replies

4. Shell Programming and Scripting

how to change specific value for a entry in the file

Hello All, can someone please suggest me a one line command to change a specific value that is associated to an entry in the file. for example #more schedulefile quartz.job.manual.bonus.schedule=0 0 9 ? * * # it should be changed to #more schedulefile... (5 Replies)
Discussion started by: bobby320
5 Replies

5. Shell Programming and Scripting

Replacing specific entry using sed

Hi guys, I'm new to bash programming, so please pardon me. I'm trying to replace an entry's text in Books.txt This code works perfectly: sed -i "s/$BookTitle/$NewBookTitle/g" Books.txt But problem is, if there are double entries, it will also replace that entry. For example: ... (12 Replies)
Discussion started by: todaealas
12 Replies

6. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

7. Programming

PYTHON COPY Contents of file1 into a specific entry in file2

file1 cat dog fish file2 This is a bunch of lines <!-- INSERT ANIMALS HERE --> horse cheetah post results file2 This is a bunch of lines <!-- INSERT ANIMALS HERE --> cat dog fish horse (1 Reply)
Discussion started by: TY718
1 Replies

8. Shell Programming and Scripting

Check first specific string after a pattern

Hi, I've a file with content as below first_block_list{ a:5 b:3 c:8 } new_store_list( a:1000 b:200 c:3343 ) first_item_list{ a:10 b:20 c:30 } second_item_list{ (1 Reply)
Discussion started by: ratheeshp
1 Replies

9. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies
Vendor(3pm)						User Contributed Perl Documentation					       Vendor(3pm)

NAME
Net::MAC::Vendor - look up the vendor for a MAC SYNOPSIS
use Net::MAC::Vendor; my $mac = "00:0d:93:29:f6:c2"; my $array = Net::MAC::Vendor::lookup( $mac ); You can also run this as a script with as many arguments as you like. The module realizes it is a script, looks up the information for each MAC, and outputs it. perl Net/MAC/Vendor.pm 00:0d:93:29:f6:c2 00:0d:93:29:f6:c5 DESCRIPTION
The Institute of Electrical and Electronics Engineers (IEEE) assigns an Organizational Unique Identifier (OUI) to manufacturers of network interfaces. Each interface has a Media Access Control (MAC) address of six bytes. The first three bytes are the OUI. This module allows you to take a MAC address and turn it into the OUI and vendor information. You can, for instance, scan a network, collect MAC addresses, and turn those addresses into vendors. With vendor information, you can often guess at what what you are looking at (e.g. an Apple product). You can use this as a module as its individual functions, or call it as a script with a list of MAC addresses as arguments. The module can figure it out. This module tries to persistently cache with DBM::Deep the OUI information so it can avoid using the network. If it cannot load DBM::Deep, it uses a normal hash (which is lost when the process finishes). You can preload this cache with the load_cache() function. So far, the module looks in the current working directory for a file named mac_oui.db to find the cache. I need to come up with a way to let the user set that location. Functions run( @macs ) If I call this module as a script, this class method automatically runs. It takes the MAC addresses and prints the registered vendor information for each address. I can pass it a list of MAC addresses and run() processes each one of them. It prints out what it discovers. This method does try to use a cache of OUI to cut down on the times it has to access the network. If the cache is fully loaded (perhaps using "load_cache"), it may not even use the network at all. lookup( MAC ) Given the MAC address, return an anonymous array with the vendor information. The first element is the OUI, the second element is the vendor name, and the remaining elements are the address lines. Different records may have different numbers of lines, although the first two should be consistent. The normalize_mac() function explains the possible formants for MAC. normalize_mac( MAC ) Takes a MAC address and turns it into the form I need to send to the IEEE lookup, which is the first six bytes in hex separated by hyphens. For instance, 00:0d:93:29:f6:c2 turns into 00-0D-93. The input string can be a separated by colons or hyphens. They can omit leading 0's (which might make things look odd). We only need the first three bytes 00:0d:93:29:f6:c2 # usual form 00-0d-93-29-f6-c2 # with hyphens 00:0d:93 # first three bytes 0:d:93 # missing leading zero :d:93 # missing all leading zeros fetch_oui( MAC ) Looks up the OUI information on the IEEE website, or uses a cached version of it. Pass it the result of "normalize_mac()" and you should be fine. The "normalize_mac()" function explains the possible formants for MAC. To avoid multiple calls on the network, use "load_cache" to preload the entire OUI space into an in-memory cache. This can take a long time over a slow network, thoug; the file is about 60,000 lines. fetch_oui_from_ieee( MAC ) Looks up the OUI information on the IEEE website. Pass it the result of "normalize_mac()" and you should be fine. The "normalize_mac()" function explains the possible formants for MAC. fetch_oui_from_cache( MAC ) Looks up the OUI information in the cached OUI information (see "load_cache"). The "normalize_mac()" function explains the possible formats for MAC. To avoid multiple calls on the network, use "load_cache" to preload the entire OUI space into an in-memory cache. If it doesn't find the MAC in the cache, it returns nothing. extract_oui_from_html( HTML ) Gets rid of the HTML around the OUI information. It may still be ugly. The HTML is the search results page of the IEEE ouisearch lookup. Returns false if it could not extract the information. This could mean unexpected input or a change in format. parse_oui( STRING ) Takes a string that looks like 00-03-93 (hex) Apple Computer, Inc. 000393 (base 16) Apple Computer, Inc. 20650 Valley Green Dr. Cupertino CA 95014 UNITED STATES and turns it into an array of lines. It discards the first line, strips the leading information from the second line, and strips the leading whitespace from all of the lines. With no arguments, it returns an empty anonymous array. load_cache( [ SOURCE ] ) Downloads the current list of all OUIs, parses it with "parse_oui()", and stores it in $Cached anonymous hash keyed by the OUIs (i.e. 00-0D-93). The "fetch_oui()" will use this cache if it exists. The cache is stored as a "DBM::Deep" file named after the "NET_MAC_VENDOR_CACHE" environment variable, or "mac_oui.db" by default. By default, this uses "http://standards.ieee.org/regauth/oui/oui.txt" , but given an argument, it tries to use that. To load from a local file, use the "file://" scheme. If "load_cache" cannot load the data, it issues a warning and returns nothing. SEE ALSO
Net::MacMap SOURCE AVAILABILITY
This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases. http://sourceforge.net/projects/brian-d-foy/ If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately. AUTHOR
brian d foy "<bdfoy@cpan.org>" COPYRIGHT AND LICENSE
Copyright (c) 2004-2007 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2007-10-28 Vendor(3pm)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy