Parsing fields from class list files to use output with newusers command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing fields from class list files to use output with newusers command
# 1  
Old 02-26-2012
Parsing fields from class list files to use output with newusers command

Hello I am trying to develop a shell script that takes a text file such as this...

Code:
E-mail@ Soc.Sec.No. *--------Name-----------* Class *School.Curriculum.Major.* Campus.Phone
JCC2380 XXX-XX-XXXX CAREY, JULIE C            JR-II BISS CPSC BS   INFO TECH   412/779-9445 
JAC1936 XXX-XX-XXXX CONSOLMAGNO, JOE A.       SO-I  BISS CPSC BS   INFO TECH   412/833-7993 
ACC4636 XXX-XX-XXXX CURRIE, ADAM C.           JR-II BISS CPSC BS   COMP SCI    724/657-0437 
SPF1696 XXX-XX-XXXX FARLEY, SEAN P.           JR-I  BISS CPSC BS   COMP SCI    814/236-2398 
SEK8835 XXX-XX-XXXX KELLEY, SHAWN E.          FR-II BISS CPSC BS   COMP SCI    724/406-7149 
MCK0599 XXX-XX-XXXX KOMISIN, MICHAEL C.       JR-I  BISS CPSC BS   COMP SCI    000/000-0000 
GJM1887 XXX-XX-XXXX MACK, GREGORY J.          SO-II BISS CPSC BS   INFO TECH   724/735-4354 
NGM5479 XXX-XX-XXXX MCINTIRE, NICHOLAS G      JR-I  BISS CPSC BS   INFO TECH   724/794-8268 
ZTP7190 XXX-XX-XXXX PETAK, ZACHARY T.         FR-II BISS CPSC BS   INFO TECH   724/406-1298 
AXS9097 XXX-XX-XXXX SAUNDERS, ALEXANDER       SO-I  BISS CPSC BS   INFO TECH   724/334-0313 
RJS6624 XXX-XX-XXXX SNYDER, ROBERT J.         SO-II BISS CPSC BS   COMP SCI    814/328-2021 
MWS1990 XXX-XX-XXXX STASNY, MATTHEW W         SO-II BISS CPSC BS   INFO TECH   412/882-0581

from the command line and then the output would be the <i>usernameSmilieassword</i>

The user name is the email name but it must be lowercase instead of uppercase, and the password is the first letters class, school, curriculum and major followed by the last 4 digits of the user's phone number.

The output of should look something like this...

Code:
jcc2380:jbci9445
jac1936:sbci7993

I am using the output with the newusers command to create new accounts in our system, but I am not very good with my parsing to produce this output


Many thanks,
Crim
# 2  
Old 02-26-2012
Assumption: file is fixed width and you want chars at 47,53,58 and 68 plus last 4 chars of input line for password.

Code:
awk 'BEGIN { c=split("47,53,58,68", A, ",") }
NR>1 {
   pw=""
   for(p=1; p<=c;p++)
        pw=pw substr($0, A[p], 1)
   print tolower($1 ":" pw substr($0,length - 3)) }' infile

# 3  
Old 02-26-2012
Code:
awk 'function f (str) {return substr(str,1,1)}
     NR>1{pw=f($(NF-6)) f($(NF-5)) f($(NF-4)) f($(NF-2));
          split($NF,a,"-");
          print tolower($1 ":" pw a[2])}' infile

# 4  
Old 02-26-2012
@rdcwayx your solution assumes that Major and Curriculum always have two words
# 5  
Old 02-26-2012
Cheers for the help both you of. And to answer your question yes Chubler the files all have the same character match up
# 6  
Old 02-27-2012
Most awks can do this too:
Code:
awk 'NR>1{split($0,c,x);print tolower($1 ":" c[47] c[53] c[58] c[68] c[88] c[89] c[90] c[91])}' infile

or:
Code:
awk 'NR>1{print tolower($1 $2 $3 $3 $5 $6 $7 ":" $47 $53 $58 $68 $88 $89 $90 $91)}' FS= infile


Last edited by Scrutinizer; 02-27-2012 at 01:46 AM..
# 7  
Old 02-27-2012
Through Sed..
Code:
sed '1d;s/^\([^ ]*\) [^ ]* [^ ]* [^ ]* [^ ]*  *\(.\)[^ ]*  *\(.\)[^ ]*  *\(.\)[^ ]* [^ ]*  *\(.\)[^ ]* [^ ]*  *.*-\(.*\)/\1:\2\3\4\5\6/;h;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Parsing through list of files

I have a requirement where I need parse through files in a directory which have a specific pattern and then check whether the file has been processed or not. The exit condition is any file that has been processed will have an entry in database. If it is processed i.e., if an entry is present for... (4 Replies)
Discussion started by: abhilashnair
4 Replies

3. Shell Programming and Scripting

Help: Parsing a file to new output files

I have an output file similar to this >HWI-ST766:129:D0WJDACXX:4:2308:16645:199681.1 /start=1 /end=100 /strand=+ Eukaryotic18S_rRNA GATTAAGCCATGCATGTGTAAGTTTAAAGTCCTAGAAGGATGAAACTGCGGACGGCTCAT TATAACAGTAATAGTTTCTTTGGTTAGTATCTATAAGGAT >HWI-ST766:129:D0WJDACXX:4:2308:2922:199946.1 /start=1... (4 Replies)
Discussion started by: fozrun
4 Replies

4. Shell Programming and Scripting

list files command output

Hi All, Below is the 2 different ouputs of the command "ls -lrt", my question is what exactly "total 0" & "total 8" means here ? $ ls -rtl total 0 -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 c -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 b -rw-r--r-- 1... (1 Reply)
Discussion started by: kannan84
1 Replies

5. Shell Programming and Scripting

AWK Compare files, different fields, output

Hi All, Looking for a quick AWK script to output some differences between two files. FILE1 device1 1.1.1.1 PINGS device1 2.2.2.2 PINGS FILE2 2862 SITE1 device1-prod 1.1.1.1 icmp - 0 ... (4 Replies)
Discussion started by: stacky69
4 Replies

6. Shell Programming and Scripting

Parsing dynamic data from a command output

Hi people, I am writing a korn shell script, and one of the command gives an output something like below: release.label.2010.03.02 objects: /project/path/to/some/file_name.ksh /project/path/another/file_name01.dat I have to retrieve the file paths one by one & use them as... (9 Replies)
Discussion started by: kiwin1000
9 Replies

7. Shell Programming and Scripting

To get an output by combining fields from two different files

Hi guys, I couldn't find solution to this problem. If anyone knows please help me out. your guidance is highly appretiated. I have two files - FILE1 has the following 7 columns ( - has been added to make columns visible enough else columns are separated by single space) 155.34 - leg - 1... (8 Replies)
Discussion started by: smriti_shridhar
8 Replies

8. Shell Programming and Scripting

How list of files apart from *.class files in certain folder

Hi Friends How to list of all files in a particular directory structure, with out listing a particular file extn. I mean to say in a folder structure I have many files ..I want to list them with out *.class files. Please help Thanks Joy (3 Replies)
Discussion started by: itsjoy2u
3 Replies

9. Shell Programming and Scripting

parsing output from a diff command...

hi, i have a script which pipes the output of a diff -rq command into a separate file/ it would read something like this: Files mod1/lala/xml/test1.txt and mod2/lala/xml/test1.txt differ Only in mod2/lala/xml: test2.txt What i need to do is to parse this file so i end up with just a... (5 Replies)
Discussion started by: kam
5 Replies

10. Shell Programming and Scripting

parsing output from ls command

I have to test the directory name which is obtained from for dir in `ls -l|grep $9 ' i need to check whether it is directory ( if yes, I have to check the first 3 character fo the directory how can I do that? Please help me thanks (3 Replies)
Discussion started by: ajaya
3 Replies
Login or Register to Ask a Question