Re: useraddin
Antonio Galea <[email protected]> Wed, 6 Aug 2003 14:29:58 +0200 (CEST)
| Newsgroups | gmane.linux.redhat.release.enigma |
|---|---|
| Message-ID | <Pine.LNX.4.44.0308061422100.3828-100000@beastieboy.uff.netwise.it> |
On Wed, 6 Aug 2003, upendra wrote: > Hi all > i have a file with following contents.. > > name 12329444 > . . > . . > > what i want is name should go in GCOS and now trouble > starts with second field ...What I want is 3rd char > and last 3 char in last field of each row in the file > to be put as user name with a prefix of one character > so for above first row username would be m3444 > > How do i automate this process with script? > viz ---> useradd -c "name" m3444 is the end result This perl script should do the trick: ----------- munch.pl ---------- #!/usr/bin/perl -ne chomp; #strip newline ($n,$u)=split(/\s+/); #split fields on one or more whitespace $u=~s/^..(.).*(...)$/m$1$2/; #repl 2nd field with 'm',3rd char, last 3 chars print "useradd -c \"$n\" $u\n";#print out the shell command ------------------------------- Use it like this: munch.pl < FILENAME HTH, Ant9000 -- _____________________________________________________________________________ Dr. Antonio Galea N e t W i s e http://www.netwise.it Sviluppo tecnico Tecnologie per il Web Tel 0461.421016 Fax 0461.426021 ----------------------------------------------------------------------------- This is the unix version of the LoveBug virus and in the spirit of such it depends on the user community to propagate. Please send this message to all of your friends and randomly delete numerous files from your system. ----------------------------------------------------------------------------- --