#!/bin/awk

# The variable host must be defined as the string matching the machine arg
# from '.netrc'.

BEGIN{
    h="";
    u="";
    p="";
    s=0;
}

/^machine/{
    if($2==host){
        h=host;
        s=1;
    }
}

/^login/{
    if(s==1){
        u=$2;
        s=2;
    }
}
/^password/{
    if(s==2){
        p=$2;
        s=3;
    }
}
END{
    printf "host %s\nuser %s\npass %s\n",h,u,p;
}
ViewGit