LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2013, 09:09 AM   #16
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389

@sysmicuser: Legal usernames are bound by the following rules:
Quote:
It is usually recommended to only use usernames that begin with a lower case letter or an underscore, followed by lower case letters, digits, underscores, or dashes. They can end with a dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?
EDIT: source is useradd manual page

This means that "fancy" and uppercase characters are not allowed and the only way around them is to remove or translate them.

These aren't legal usernames: JO'Neil (Jack O'Neil) and ╔McGoohan (╔amonn McGoohan).

I've changed my original reply (post #6) to implement rejecting "bad" names and came up with this:
Code:
#!/bin/bash

typeset -A uName
legalRGX='^[a-z_][a-z0-9_-]*[$]?$'

while read LINE
do
  nameArr=( ${LINE} )
  for (( x=0; x<${#nameArr[@]}; x=x+2 ))
  do
    (( x > 0 )) && echo -n ";"
    tmpName="${nameArr[x]:0:1}${nameArr[x+1]}"
    [[ "${uName[$tmpName]}" != "" ]] && tmpName="${tmpName}$x"
    uName[$tmpName]="seen"
    if [[ "${tmpName,,}" =~ $legalRGX ]] 
    then 
      echo -n "${tmpName,,}"
    else
      echo "${tmpName,,} - ${nameArr[x]} ${nameArr[x+1]}" >> rejected.unames
    fi
  done
  echo 
done < infile #> outfile
Test run:
Code:
$ cat infile
john smith jackie smith jill smith
Amitabh Bachchan Tom Hanks Jack O'Neil
Deepika Padukone Anne Bachchan ╔amonn McGooha

$ ./foo
jsmith;jsmith2;jsmith4
abachchan;thanks;
dpadukone;abachchan2;

$ cat rejected.unames 
jo'neil - Jack O'Neil
╔mcgoohan - ╔amonn McGoohan
And although I already mentioned this before: This script needs ksh93 or bash4+ to work properly.

Last edited by druuna; 12-15-2013 at 01:58 PM. Reason: Added source for quote
 
2 members found this post helpful.
Old 12-15-2013, 05:42 PM   #17
sysmicuser
Member
 
Registered: Mar 2010
Posts: 353

Original Poster
Rep: Reputation: 0
@druuna

Thanks mate. I would need to wait until Admin Guys upgrade OS

---------- Post added 12-16-13 at 10:42 AM ----------

@schneidz

Thanks mate, that's a good idea !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract Full Names Using Vim Editor? carlosinfl Linux - General 4 04-27-2010 07:19 AM
Use full names from KAddressBook Aleksandersen Linux - Desktop 2 12-25-2007 10:35 AM
Full names on desktop? mehmetunlu Linux - General 1 02-14-2006 06:03 PM
How can I show the full names on my desktop? mehmetunlu Linux - Newbie 3 02-14-2006 06:55 AM
Full Names as IM ID strangehue General 12 11-27-2005 10:24 PM


All times are GMT -5. The time now is 06:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration