Find the answer to your Linux question:
Results 1 to 2 of 2
I have a list of student information and i need to out put the username and make a password. Below I have a very non effectient way of doing so. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2012
    Posts
    15

    Username And password script


    I have a list of student information and i need to out put the username and make a password. Below I have a very non effectient way of doing so. Will be modified later to be more efficiant. The problem I am running into is that i want everything to line up vertically for example:

    Username Password
    jaw1225 abcd
    ton1335 kbde

    instead of:

    username
    jaw1225
    ton1335
    Password
    a
    b
    c
    d
    e
    k
    b
    d
    e

    echo "USERNAME"
    awk '{print tolower($1)}' studentlist

    echo "PASSWORD"

    awk '{print tolower(substr($4,1,1))}' studentlist
    awk '{print tolower(substr($5,1,1))}' studentlist
    awk '{print tolower(substr($6,1,1))}' studentlist
    awk '{print tolower(substr($7,1,1))}' studentlist


    Any help would be greatly appreciated thank you

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    211
    hi,

    Code:
    awk '{if(FNR==1){
       U[++u]=tolower($1)
       P[++p]=$2
    }else{
       U[++u]=$1
       n=split($2,a,"")
       for(i=1;i<=n;i++)P[++p]=a[i]
    } }
    END{
       for(i=1;i<=u;i++)print U[i]
       for(i=1;i<=p;i++)print P[i]}'
    rtfm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •