Hi,
I've a user alias file in the below format.. I need to change all the ID's that come after the = sign (with some multiple ID's which are separated by comma's) to their respective users that are contained in the passwords file.. Whats the best way to go about this.. Some sort of sed command in a loop using grep?
I'm really not familiar with this kind of stuff...
Alias File format
KVHPOJNOTES=x1565275,x0997695
INES=uc00275,uc01522,uc00286,uc01640,uc01672,uc01940,uc01941
KVHNOTESIDAHMLB=ahml02
KVHNOTESIDAHUBA=ahub01,uc01640
KVHNOTESIDALMLD=alml02
KVHNOTESIDALMLE=alml04
If I changed the file that all the deliminators (the = and ,) were a space, would it start off something like this?
awk -F" " '{ for ( i=2; i<=NF; i++ )
[root@node2 ~]# cat infile
KVHPOJNOTES=x1565275,x0997695
INES=uc00275,uc01522,uc00286,uc01640,uc01672,uc01940,uc01941
KVHNOTESIDAHMLB=ahml02
KVHNOTESIDAHUBA=ahub01,uc01640
KVHNOTESIDALMLD=alml02
KVHNOTESIDALMLE=alml04
[root@node2 ~]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
[root@node2 ~]# awk -F[:=] 'NR==FNR{a[FNR]=$1}NR>FNR{$1=$1"="a[FNR];print $1}' passwd infile
KVHPOJNOTES=root
INES=bin
KVHNOTESIDAHMLB=daemon
KVHNOTESIDAHUBA=adm
KVHNOTESIDALMLD=lp
KVHNOTESIDALMLE=sync
methyl
June 15, 2012, 12:45pm
3
Another interpretation of post #1 . Look up each alias in /etc/passwd .
cat alias.lst | cut -f2 -d= | tr ',' '\n' | sort | uniq | while read username
do
echo "Checking username: ${username}"
grep \^${username}: /etc/passwd
done