Sponsored Content
Top Forums Shell Programming and Scripting Perl : how to match non-empty string that has no spaces Post 302557626 by togr on Wednesday 21st of September 2011 05:36:16 PM
Old 09-21-2011
Perl : how to match non-empty string that has no spaces

Hi Everyone,

I am looking for neat way to grep a non-empty string that basically contains a hostname, which might be in FWDN form or without the domain, for example:

hostname.internal.domainname.net

The file I am parsing contains blan lines (^$) and also series of "-" which in other places are used as separator (-----------------------).

As you of course know hyphen ("-") may well occur in a hostname.

if (/\S/) - is not good as it catches "--------------" too
if (! /\s/) - is not good either for the same reason

I was playing with regexes like: /[A-Za-z0-9.-]+/ but couldn't get what I actually need. That matched series of hyphens either. I need a regex that would allow for hyphens but denied "hyphens only". In other words hyphens are permitted but only when there are other letters as well.

I was able to get around my problem using two or three if... tests but this problem is still sitting in the back of my head.

I think I made my explanation unclear... apologies for that. Be sure I'll be seeking for answer myself tooSmilie
Kind regards to Everyone.
 

10 More Discussions You Might Find Interesting

1. Programming

Removing empty spaces and adding commas

I have a file which contains numbers as follows: 1234 9876 6789 5677 3452 9087 4562 1367 2678 7891 I need to remove the empty spaces and add commas between the numbers like: 1234,9876,6789,5677,3452, 9087,4562,1367,2678,7891 Can anyone tell me the command to do... (4 Replies)
Discussion started by: jazz
4 Replies

2. Shell Programming and Scripting

Perl: Better way to match string within a string

Hi, I'm trying to get one field out of many as follows: A string of multiple fields separated with "/" characters: "/ab=12/cd=34/12=ab/34=cd/ef=pick-this.one/gh=blah/ij=something/" I want to pick up the field "ef=pick-this.one" which has no regular pattern except it starts with "ef=xxxx"... (3 Replies)
Discussion started by: Juha
3 Replies

3. Shell Programming and Scripting

pattern match url in string / PERL

Am trying to remove urls from text strings in PERL. I have the following but it does not seem to work: $remarks =~ s/www\.\s+\.com//gi; In English, I want to look for www. then I want to delete the www. and everything after it until I hit a space (but not including the space). It's not... (2 Replies)
Discussion started by: mrealty
2 Replies

4. Shell Programming and Scripting

Initializing empty string with spaces

Hi, I want to Initialize a String with 50 spaces. I can do that by ex: Var1=" " But i dont want to do in this way? Is there any unix command where i can specify no of spaces to a varaible? like space(50) (1 Reply)
Discussion started by: Shiv_18
1 Replies

5. Shell Programming and Scripting

delete empty spaces at specific column

Hi All, If anybody could help me with my scenario here. I have a statement file. Example of some content: DATE DESC Debit Credit Total Rate 02-Jan-08 Lodgement 200.00 1200.00 2.51 14-Sep-07 Withdrawal 50.00 1000.00 ... (8 Replies)
Discussion started by: yonez
8 Replies

6. Shell Programming and Scripting

awk ignores fields with only spaces or empty

Hi, Does any one know how to avoid the scenario where awk ignores the fields having only spaces or empty fields? for instance, Data: "a","b","c","d",""," " code: awk -F, '{ print NF }' File the output I get is 4 instead of 6 do you know how to avoid this? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies

7. Shell Programming and Scripting

Match hex value in string (Perl)

I am trying to match a character return from a website so that I can replace it. It is the '...' character (didnt even know it existed initially). The character apparently has the hex value of 2026, but in the script, attempting to substitute regular 3 periods is not working. What am I... (2 Replies)
Discussion started by: Guyverix
2 Replies

8. Shell Programming and Scripting

perl regex string match issue..kindly help

i have a script in which i need to skip comments, and i am able to achieve it partially... IN text file: {**************************** {test : test...test } Script: while (<$fh>) { push ( @data, $_); } if ( $data =~ m/(^{\*+$)/ ){ } With the above match i am... (5 Replies)
Discussion started by: avskrm
5 Replies

9. Shell Programming and Scripting

String match, with perl command

cat clinvar_00-latest.vcf | perl -aF/\\t/ -lne '/CLNSRCID=(\d+)/ and print join("\t",@F,$1)' > OMIM.txt The above code finds the text CLNSRCID=, but only outputs those records in which there is a numerical value only. For example, the first match is CLNSRCID=103320.0001 in line 4 of the... (1 Reply)
Discussion started by: cmccabe
1 Replies

10. Shell Programming and Scripting

Remove trailing empty spaces within a quote

Platform: Oracle Linux 6.5 I have a file with hundreds of values enclosed in single quotes like below. I want the trailing empty spaces before the ending quote to be removed. Expected output shown below. Can this be done using good old vi editor ? Or should I use sed or awk for this ? $ cat... (4 Replies)
Discussion started by: kraljic
4 Replies
netgroup(4)															       netgroup(4)

NAME
netgroup - list of network groups SYNOPSIS
/etc/netgroup A netgroup defines a network-wide group of hosts and users. Use a netgroup to restrict access to shared NFS filesystems and to restrict remote login and shell access. Network groups are stored in a network information services, such as LDAP, NIS, or NIS+, not in a local file. This manual page describes the format for a file that is used to supply input to a program such as ldapaddent(1M) for LDAP, makedbm(1M) for NIS, or nisaddent(1M) for NIS+. These programs build maps or tables used by their corresponding network information services. Each line of the file defines the name and membership of a network group. The line should have the format: groupname member... The items on a line can be separated by a combination of one or more spaces or tabs. The groupname is the name of the group being defined. This is followed by a list of members of the group. Each member is either another group name, all of whose members are to be included in the group being defined, or a triple of the form: (hostname,username,domainname) In each triple, any of the three fields hostname, username, and domainname, can be empty. An empty field signifies a wildcard that matches any value in that field. Thus: everything (,,this.domain) defines a group named "everything" for the domain "this.domain" to which every host and user belongs. The domainname field refers to the domain in which the triple is valid, not the domain containing the host or user. In fact, applications using netgroup generally do not check the domainname. Therefore, using (,,domain) is equivalent to (,,) You can also use netgroups to control NFS mount access (see share_nfs(1M)) and to control remote login and shell access (see hosts.equiv(4)). You can also use them to control local login access (see passwd(4), shadow(4), and compat in nsswitch.conf(4)). When used for these purposes, a host is considered a member of a netgroup if the netgroup contains any triple in which the hostname field matches the name of the host requesting access and the domainname field matches the domain of the host controlling access. Similarly, a user is considered a member of a netgroup if the netgroup contains any triple in which the username field matches the name of the user requesting access and the domainname field matches the domain of the host controlling access. Note that when netgroups are used to control NFS mount access, access is granted depending only on whether the requesting host is a member of the netgroup. Remote login and shell access can be controlled both on the basis of host and user membership in separate netgroups. /etc/netgroup Used by a network information service's utility to construct a map or table that contains netgroup information. For example, ldapaddent(1M) uses /etc/netgroup to construct an LDAP container. Note that the netgroup information must always be stored in a network information service, such as LDAP, NIS, or NIS+. The local file is only used to construct a map or table for the network information service. It is never consulted directly. nis+(1), ldapaddent(1M), makedbm(1M), nisaddent(1M), share_nfs(1M), innetgr(3C), hosts(4), hosts.equiv(4), nsswitch.conf(4), passwd(4), shadow(4) netgroup requires a network information service such as LDAP, NIS, or NIS+. Applications may make general membership tests using the innetgr() function. See innetgr(3C). Because the "-" character will not match any specific username or hostname, it is commonly used as a placeholder that will match only wild- carded membership queries. So, for example: onlyhosts (host1,-,our.domain) (host2,-,our.domain) onlyusers (-,john,our.domain) (-,linda,our.domain) effectively define netgroups containing only hosts and only users, respectively. Any other string that is guaranteed not to be a legal username or hostname will also suffice for this purpose. Use of placeholders will improve search performance. When a machine with multiple interfaces and multiple names is defined as a member of a netgroup, one must list all of the names. See hosts(4). A manageable way to do this is to define a netgroup containing all of the machine names. For example, for a host "gateway" that has names "gateway-subnet1" and "gateway-subnet2" one may define the netgroup: gateway (gateway-subnet1,,our.domain) (gateway-subnet2,,our.domain) and use this netgroup "gateway" whenever the host is to be included in another netgroup. 22 Jul 2004 netgroup(4)
All times are GMT -4. The time now is 05:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy