Sponsored Content
Top Forums Shell Programming and Scripting Substituting field contents using AWK Post 302366743 by Glyn_Mo on Friday 30th of October 2009 08:51:22 AM
Old 10-30-2009
This is the desired output.
Code:
UserID              Process ID      Time Active          Licence Type   User Name
------              ----------      -----------          ------------   ---------
z310084             1079            start Fri 11:43      ChangeBase     J Bloggs
z004021             1618            start Fri 11:53      ChangeBase     A Bloggs
ChangeAdmin         2155            start Fri 5:30       ChangeBase     
z001698             1994            start Fri 12:02      ChangeBase     C Bloggs
z600969             1885            start Fri 9:21       CMBase         D Bloggs
oracled             2083            start Fri 10:51      CMBase         Oracle DBA
z001698             2380            start Fri 10:55      CMBase         F Bloggs
z311361             1393            start Fri 11:29      CMBase         G Bloggs
u414014             580             start Fri 7:58       CMBase         H Bloggs
z310086             1409            start Fri 11:44      CMBase         I Bloggs
 
Users of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of 4  licences in use)
Users of SYNERGY-CMBase: (Total of 12 licenses issued; Total of 6  licences in use)

I already have a shell script and a couple of awk scripts which worked fine and displayed all of the above with the exception of "User Name".

These scripts as follows:
Script cmsynergy_licence_admin.sh
Code:
LICENCEFILE=$HOME/cmsynergy_licences
LICENCE_COUNT_OUTPUT=$HOME/output_of_cmsynergy_licences
FORMATTED_LICENCE_COUNT=$HOME/formatted_licence_count
view_licences()
{
clear
ccm set role ccm_admin
LINENUM=1
/agsdev/continuus/flexnet/lmutil lmstat -a -c /agsdev/continuus/flexnet/license.dat > $LICENCEFILE
nawk -f /agsdev/continuus/ccm_root/bin/cmsynergy_count_licences.awk $LICENCEFILE > $LICENCE_COUNT_OUTPUT
sed 's/$/ CMBase/' $LICENCE_COUNT_OUTPUT > $FORMATTED_LICENCE_COUNT
nawk -F" " -f /agsdev/continuus/ccm_root/bin/cmsynergy_display_licences.awk $FORMATTED_LICENCE_COUNT
INC_BY=`nawk -F" " -f /agsdev/continuus/ccm_root/bin/cmsynergy_display_licences.awk $FORMATTED_LICENCE_COUNT | wc -l`
delete_temp_files
LINENUM=`echo "$LINENUM + $INC_BY -1" | bc`
print_line 1 "View username holding a licence...............[1]"
print_line 1 "Terminate a SYNERGY-CMBase licence............[2]"
print_line 1 "Return to Main Menu...........................[9]"
print_line 1 "Select an option [ ]"
tput cup $LINENUM 19
read V_OPTION
if [ -z "$V_OPTION" ]
then
V_OPTION=0
fi
case "$V_OPTION" in
'1')
print_line 1
print_line 1 "Enter the User ID: "
read USERNAME
print_line 1
ypmatch $USERNAME passwd | nawk -F: '{ print $5 }'
print_line 1
print_line 1 $BOLD_ON"Press return to continue..."$BOLD_OFF
read x
view_licences
;;
'2')
kill_process
;;
'9')
main_menu
;;
*)
view_licences
;;
esac
}
kill_process()
{
print_line 1 "Enter the Process ID of the SYNERGY-CMBase licence you wish to terminate: "
read PID
ask_yesno "ARE YOU SURE? y/n [ ]"
if [ $? -eq 0 ]
then
clear
LINENUM=1
/agsdev/continuus/flexnet/lmutil lmremove -c /agsdev/continuus/flexnet/license.dat -h SYNERGY-CMBase Phys-agsdev 19353 $PID
print_line 1
print_line 1 "Terminating licence associated with $PID..."
sleep 1
# print_line 1 $BOLD_ON"Press return to continue..."$BOLD_OFF
# read x
view_licences
else
echo
echo "Cancelling the termination of Process ID $PID..."
sleep 1
view_licences
fi
view_licences
}
delete_temp_files()
{
rm $LICENCEFILE
rm $LICENCE_COUNT_OUTPUT
rm $FORMATTED_LICENCE_COUNT


Script cmsynergy_display_licences.awk
Code:
BEGIN   {
        print ""
        print "User                 Process ID      Time Active          Licence Type"
        print "----                 ----------      -----------          ------------"
        }
NF > 12{changebaselicences++}
NF < 13{cmbaselicences++}
{
gsub(/\(/, " ", $0)
gsub(/\)/, " ", $0)
gsub(","," ", $0)
gsub("linger: 1800","ChangeBase", $0)
print $4, "     ", "  ", $7, "  ", "  ", $8, $9, $11, " ", $12
}
END     {
        printf "\nUsers of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of %-2d", changebaselicences
        print " licences in use)"
        printf "\nUsers of SYNERGY-CMBase: (Total of 12 licenses issued; Total of %-2d", cmbaselicences
        print " licences in use)" 
        print ""
        print "  NOTE: It is not possible to terminate SYNERGY-ChangeBase licences"
        print ""
        }

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove spaces from first field, and write entire contents into other text file

Hi all, I have searched and found various threads about removing spaces from a field within a text file. Unfortunately, I have not found exactly what I'm looking for, nor am I adept enough to modify what I've found into what I need. I use the following command to remove the first line... (3 Replies)
Discussion started by: carriehoff
3 Replies

2. Shell Programming and Scripting

Join file contents via common field

I have 2 files with a common parm - Jobname File 1 0507 1202 JOBA 0507 1302 JOBB 0507 1452 JOBC 0507 1552 JOBA 0507 1553 JOBA File2 JOBA abcdefg server4 JOBB defghij server22 JOBC vwxyz12 server55 I would like to take each line from File1 and match the jobname with the jobname... (8 Replies)
Discussion started by: Northerner
8 Replies

3. Shell Programming and Scripting

Substituting variable value in AWK /start/,/stop/

Hi all u brilient people on the forum... I am trying to call the variable value in awk command for search pattern /start/,/stop/ but i am nt able to do this .... wat i did is ..i have created two variable YESTERDAY and TODAY and passed the y'day n 2'days dates in it...like this ... (14 Replies)
Discussion started by: whomi
14 Replies

4. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

5. UNIX for Dummies Questions & Answers

substituting variable value in AWK

Hi All, my requirement is as below. I need to replace a value in a particular column with a substitution variable(date value) and modified value of the current column value in the same position. for ex. i have a record like 02;aaaa;bbbbb;cccccc;dddddd;123456789;hhhhh;12hs;asdf ;... (3 Replies)
Discussion started by: ganesh_248
3 Replies

6. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

7. Shell Programming and Scripting

awk to update value in field of out file using contents of another Ask

In the out.txt below I am trying to use awk to update the contents of $9.. If $9 contains a + or - then $8 of out.txt is used as a key to lookup in $2 of file. When a match ( there will always be one) is found the $3 value of that file is used to update $9 of out.txt separated by a :. So the... (6 Replies)
Discussion started by: cmccabe
6 Replies

8. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

awk to change contents of field based on condition in same file

In the awk below I am trying to copy the entire contents of $6 there may be multiple values seperated by a ;, to $8, if $8 is . (lines 1 and 3 are examples). If that condition $8 is not . (line2 is an example) then that line is skipped and printed as is. The awk does execute but prints the output... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies
All times are GMT -4. The time now is 01:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy