- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 04:23 AM
08-04-2004 04:23 AM
for PWDRECORD in `cat '/etc/passwd'`
do
LOG_ID=`echo $PWDRECORD|cut -d':' -f1`
COSMO_ID=`echo $PWDRECORD|cut -d',' -f4`
if [ "$LOG_ID" = "" -o "$COSMO_ID" = "" ]
then
continue
fi
if [ `echo "$COSMO_ID" | grep ":" > /dev/null` ]
then
continue
fi
STUDENT_EMPLOYEE=`echo $PWDRECORD|cut -d ',' -f5`
STUDENT_EMPLOYEE=`echo $STUDENT_EMPLOYEE | cut -c1`
( echo $COSMO_ID | grep $LOG_ID >/dev/null )|| ( [ ! "$COSMO_ID" = "0" ] && \
echo $COSMO_ID","$LOG_ID","$STUDENT_EMPLOYEE >> /tmp/bbids.list )
unset LOG_ID
unset COSMO_ID
unset STUDENT_EMPLOYEE
done
TIA and points for all responses.
Sean
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 05:37 AM
08-04-2004 05:37 AM
Re: Scripting help
while IFS=: read LOG_ID x x x FIELD5 x
do
typeset -L1 STUDENT_EMPLOYEE
echo $FIELD5 | IFS=, read x x x COSMO_ID STUDENT_EMPLOYEE x
[[ -z "$LOG_ID" || -z "$COSMO_ID" || "$COSMO_ID" = *:* ]] && continue
[[ ! $COSMO_ID = *$LOG_ID* && ! "$COSMO_ID" = "0" ]] && echo "$COSMO_ID,$LOG_ID,$STUDENT_EMPLOYEE"
unset COSMO_ID
unset STUDENT_EMPLOYEE
unset STUDENT_EMPLOYEE
done < passwd
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:08 AM
08-04-2004 06:08 AM
Re: Scripting help
If so, I can write an awk script that should be fairly clean for this.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:15 AM
08-04-2004 06:15 AM
Re: Scripting help
awk -F":" '{
logId=$1;
l1=length(logId);
# if logId = "" do next record
if ( l1 == 0 ) next;
gecos=$5;
split(gecos,a,",");
cosmoId=a[4];
l1=length(cosmoId);
if ( l1 == 0 ) next;
if ( cosmoId ~ ":" ) next;
stdEmp=substr(a[5],1,1);
if ( cosmoId !~ logId && cosmoId != "0" )
print cosmoId,logId,stdEmp;
}' >/tmp/bbids.list
that is a good start on an awk script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:17 AM
08-04-2004 06:17 AM
Re: Scripting help
Can you take a minute to explain to me what this is doing? I mean your script and how it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:20 AM
08-04-2004 06:20 AM
Re: Scripting help
Kent, here's sample input:
aaronk:x:43280:20:Aaron,Karema,D,0296002,S:/false/home:/bin/false
and output:
0296002,aaronk,S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:25 AM
08-04-2004 06:25 AM
Re: Scripting help
That's pretty close except that it is putting spaces instead of commas between the entries. I stuck in commas, but it still puts in the spaces. Is there a way to suppress the spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:29 AM
08-04-2004 06:29 AM
Re: Scripting help
hmm, not quite right, even after I stripped out the spaces manually:
bbids.list is the orig, bbids.lst2 is from your script:
root@cosmo0:/tmp/sean-> diff bbids.list bbids.lst2
1c1
< 9123456,aaaaaaaa,S
---
> 9.12346e+06,aaaaaaaa,S
267c267
< 8675309,acme001,S
---
> 8.67531e+06,acme001,S
2869c2869
< EXM20031026023108.CSV:0924004,ashleyt,E
---
> EXM20031026023108.CSV,ashleyt,
20019c20019
< 8888888,doofusj,E
---
> 8.88889e+06,doofusj,E
68532c68532
< 9876543,ptest,E
---
> 9.87654e+06,ptest,E
Here are the original entries for those records.
doofusj:x:72495:20:Doofus,Joe,P,8888888,E:/home/doofusj:/usr/local/matc/bin/cosmo
ptest:x:99910:20:Fanning,Pete,W,9876543,E:/home/ptest:/usr/local/matc/bin/cosmo
ashleyt:x:38154:20:Ashley,Terry,,EXM20031026023108.CSV:0924004,E:/home/ashleyt:/usr/local/matc/bin/cosmo
acme001:x:50000:20:Neumann,Alfred,E,8675309,S:/false/home:/bin/false
aaaaaaaa:x:1909:20:TestLast,TestFirst,M,9123456,S:/false/home:/bin/false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:30 AM
08-04-2004 06:30 AM
Re: Scripting help
awk '{FS=":"; u5=$5; p2=$1; $0=u5; FS=","; print $4","p2","$5;}' passwd
Essentially we are printing the fourth part of the fifth field then a comma then the first field then the fifth part of the fifth field.
Hope that helps.
Oz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:36 AM
08-04-2004 06:36 AM
Solutioncat /etc/passwd |
awk -F":" '{
logId=$1;
# if logId = "" do next record
if ( ! logId ) next;
gecos=$5;
split(gecos,a,",");
cosmoId=a[4];
if ( ! cosmoId ) next;
stdEmp=substr(a[5],1,1);
if ( cosmoId !~ logId && cosmoId != "0" )
print cosmoId,logId,stdEmp;
}' >/tmp/bbids.list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:39 AM
08-04-2004 06:39 AM
Re: Scripting help
printf("%s,%s,%s\n",cosmoId,logId,stdEmp);
instead of
print cosmoId,logId,stdEmp;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 06:43 AM
08-04-2004 06:43 AM
Re: Scripting help
BEGIN {IFS=":";OFS=","}
{
LOG_ID = $1;
split($0,commas,",");
COSMO_ID=commas[3];
if (LOG_ID COSMO_ID == "") { next };
STUDENT_EMPLOYEE=substr(commas[4],1,1);
if (index(COSMO_ID,LOG_ID) || (COSMO_ID != 0)) {
print COSMO_ID, LOG_ID, STUDENT_EMPLOYEE >> "/tmp/bbid.lst";
}
}
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2004 07:08 AM
08-04-2004 07:08 AM
Re: Scripting help
I knew I could count on the ITRC forum crew!