Shell script method. With hindsight the processing would have been easier by reading the file backwards!
Lose the "cut" for the final version.
Script reads each line (ignoring blank lines and lines starting #role) and saves the value of "group" and saves each user role record until it finds a Description line .. when it outputs one reformatted line for each user role line. These lines are sorted to alphabetic order using "sort" on the whole output of the Shell block.
Code:
#!/bin/ksh
workfile=/tmp/`basename $0`.tmp
>${workfile}
#
echo "Login ID Appl Func Title Code Appl Func Title Code Description"
(
grep -v \^\#"role" filename.txt | sed -e "/^$/d" | while read line
do
echo "${line}"|awk -F: '{print $1,$2}' | \
read description_record description_text
if [ "${description_record}" = "#Description" ]
then
# End of data block processing. Read back role lines
cat ${workfile} | while read line2
do
echo "${line2}"|awk -F\. '{print $1,$2,$3}' | \
read record_type role rest
echo "${rest}"|awk -F\= '{print $1,$2}' | \
read user_group1 user_group2
# Display final user record
echo "${user_group2} ${save_group} ${description_text}" | \
cut -c1-70
done
#
>${workfile}
save_group=""
continue
fi
echo "${line}"|awk -F\. '{print $1,$2,$3}' | \
read record_type role rest
echo "${rest}"|awk -F\= '{print $1,$2}' | \
read user_group1 user_group2
#
# Save group name
if [ "${user_group1}" = "group" ]
then
save_group="${user_group2}"
continue
fi
#
# Save user role records until we see a Description record
echo "${line}" >> ${workfile}
done
) | sort
#
rm ${workfile}
Login ID Appl Func Title Code Appl Func Title Code Description
admin ImpactUser Allow users to login in to Impact, start and stop ser
admin NetcoolAdmin Allow users to login in to Impact, start and stop s
admin OpViewUser Allow users to login in to Impact, start and stop ser
dd12345 ImpactUser Allow users to login in to Impact, start and stop s
dd12345 OpViewUser Allow users to login in to Impact, start and stop s
rr76767 OpViewUser Allow users to login in to Impact, start and stop s
ss76767 ImpactUser Allow users to login in to Impact, start and stop s
ss76767 NetcoolAdmin Allow users to login in to Impact, start and stop
ss76767 OpViewUser Allow users to login in to Impact, start and stop s
Note: The Descriptions in your example output do not match the Descriptions in the data.
Hello,
I am having 1800 files in a directory with a specified format, like
amms_850o_prod.000003uNy
amms_850o_prod.000003u8x
amms_850o_prod.000003taP
amms_850o_prod.000003tKy
amms_850o_prod.000003si4
amms_850o_prod.000003sTP
amms_850o_prod.000003sBg
amms_850o_prod.000003rvx... (12 Replies)
Hi,
I have a situation where I want to ignore few users from list of users and print rest of user in log file.
say, I want to ignore aaa, bbb, ccc, ddd .. ppp from list of 20 user (do not want to include)
What is the good command or any script?
Thanks in advance. (1 Reply)
Hi,
I have a shell script, which reads a *.txt file - line by line. In this text file, I have some lines beginning with "#" that I want to ignore :
MY_FILE
#blah blah blah 1
blah blah blah 2
blah blah blah 3
#blah blah blah 4
I want my script to read only the following lines... (3 Replies)
Hi, I'm new to the world of UNIX and have been asked to create a complex script (at least complex to me:confused:) for AIX UNIX to create a report of all the users on the server including server, user, UID, groups, GID, etc.
Found a script using lsuser, but the output is still lacking. 2 things I... (2 Replies)
Hi,
I currently use a script to extract *.deb files located in a Directory called
"/var/mobile/Media/Downloads"
The Problem is howver I want the script to ignore the folder:
"/var/mobile/Media/Downloads/New Debs and Files"
(it shall NOT decompile any of the files in that folder.
Here is... (2 Replies)
Hi,
In the following output you can see the the user "richard" is a member on the team/group "developers":
# id richard
uid=10247(richard) gid=100361(developers) groups=100361(developers),10053(testers)
but in the following details of the said group (developers), the said user... (3 Replies)
Hi,
I have text file as shown below.
root 25 oracle 25 batch 30 griduser 32 admin 35
root 25 oracle 25 batch 30 griduser 32
oracle 25 batch 30 griduser 32 xuser 45 admin 35
I want to group by based on user name, and the output need to be as below. Not necessary the username to be... (10 Replies)
Hello All,
I saw this problem on one of the forum and solved it using group-by in oracle sql, though I am a bit curious to implement it using shell script :
There is a file having number of operations :
Opeation,Time-Taken
operation1,83621
operation2,72321
operation3,13288... (11 Replies)
Hi All,
I am trying to use below syntax to find ignore multiple locations while searching for a file.
find / -name "$serviceitem" ! -size 0 2>&1 |egrep -v "tmp|docker|WinSxS|Permission|HISTORY|alternatives|bearer11ssl|manifest"
I tried to assign all the ignore strings to one variable... (2 Replies)
Discussion started by: sravani25
2 Replies
LEARN ABOUT FREEBSD
lastlogin
LASTLOGIN(8) BSD System Manager's Manual LASTLOGIN(8)NAME
lastlogin -- indicate last login time of users
SYNOPSIS
lastlogin [-f file] [-rt] [user ...]
DESCRIPTION
The lastlogin utility will list the last login session of each specified user, or for all users by default. Each line of output contains the
user name, the tty from which the session was conducted, any hostname, and the start time for the session.
If more than one user is given, the session information for each user is printed in the order given on the command line. Otherwise, informa-
tion for all users is printed. By default, the entries are sorted by user name.
The lastlogin utility differs from last(1) in that it only prints information regarding the very last login session. The last login database
is never turned over or deleted in standard usage.
The following options are available:
-f file
Open last login database file instead of the system-wide database.
-r Print the entries in reverse sorted order.
-t Sort the elements by last login time, instead of user name.
FILES
/var/log/utx.lastlogin last login database
SEE ALSO last(1), getutxent(3), ac(8)AUTHORS
John M. Vinopal wrote this program in January 1996 and contributed it to the NetBSD project.
BSD June 6, 2011 BSD