Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP EXTRACTING DATA FROM MULTIPLE LINES OF A FILE 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I am trying to extract some data from a file which contains information about users' accounts. There are approximately 20 lines of information per user, however I am only interested in a few fields from each line. Below is a sample of some of the lines in the file.

Username: USER1 Owner: Joe Schmoe
Account: SYSTEMS UIC: [16,226] ([PRTMGR,USER])
CLI: DCL Tables: DCLTABLES
Default: USER:[USER1]
LGICMD:
Flags: DisUser
Primary days: Mon Tue Wed Thu Fri
Secondary days: Sat Sun
Primary 000000000011111111112222 Secondary 000000000011111111112222
Day Hours 012345678901234567890123 Day Hours 012345678901234567890123
Expiration: (none) Pwdminimum: 6 Login Fails: 0
Pwdlifetime: 30 00:00 Pwdchange: 30-JUL-2002 15:11
Last Login: 15-AUG-2002 14:58 (interactive), 23-NOV-2001 11:24 (non-interactive)

I would like to extract the following fields for all users who have more than 1 login failure: Username, Owner, Login Fails, and Last Login.

Any help would be greatly appreciated.

Thanks,

John
 
Parse the data by using the colon as your field separator,
use the first fields value as an index and treat index + 1
as your value. Make sure that you delimit your fields after
the colon. Otherwise you will grab the next fields index.

I won't do this without seeing some more effort first.
At least give it a try on your own. Awk can do this pretty
capably, sed also, and a while loop with either tool or
IFS and cut can work.
 
I tried using something like the following, but I can't seem to get it working.

egrep '^Username|^Flags|^Expiration|^Login' | nawk '{print $0}' | cut -c 1-25,50-70 | nawk -f 'BEGIN{RS=""; FS="\n" ORS="\n"}{print $1,$2 "\n"}'


John
 
Hi,

I'll start you off with this which just puts the USER and EXPIRES in final.dat. I'm sure you can make some final modifications to the code to get exactly what you want. I already worked it out in my head.

My datafile contained 10 user records that I cut and pasted into it from this forum and then I modified the USERID and EXPIRES fields for test purposes

################################start

#!/bin/ksh

FILE=final.dat
>$FILE
EXPIRE=0
cat datafile|while read line
do
USER=`echo $line|grep Username|nawk '{print $2}' 2> /dev/null`
if [ -n "$USER" ]
then
STRING=$USER
fi

EXPIRE=`echo $line|grep Expiration|nawk '{print $7}' 2> /dev/null`
if [ -z "$EXPIRE" ]
then
continue
elif [ $EXPIRE -gt 0 ]
then
echo "$STRING:$EXPIRE">>$FILE
fi
done


ART
 
Art15t,

With the start that you gave me I was able to get exactly what I was looking for!! Thank you very much for your help. I really appreciate it!!

Thanks,

John
 
Damn it's hard to write this with my head on it's side.

You're wecome John


ART
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top