PERL Script Help

dfnkt

Senior member
May 3, 2006
434
0
76
Looking for some help with a perl script.

I need to parse a .txt file I have of our active directory user "Display Names". The list contains approximately 6,000 names, trying to get a perl script that can read the list one by one and print the display name only if it contains a space.

for example:
user1
user2
John Doe
user3
Jane Doe

In the above example the script should print John Doe and Jane Doe while skipping the users that have no space.

The reasoning behind this is that we have a ton (probably 2,500 or more) "novelty/service" accounts that are not real users.

I tried defining all the users in the script such as @adusers = qw(insert users here) and then doing a $_ = /\s/; regex but to no avail.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
#!/usr/bin/perl

open(FH, "test.txt");

while (<FH>)
{
print if (/\S\s+\S/);
}
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
#!/usr/bin/perl

open(FH, "test.txt");

while (<FH>)
{
print if (/\S\s+\S/);
}

Too long! :p

Here's a one-liner version:

perl -ne "print if (/\S\s+\S/)" test.txt
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Bah, you want short use grep:

grep ' ' test.txt (non-robust)
grep '\w \w' test.txt (more robust)