Visit Our UNIX and Linux User Community


greping $2 into a list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting greping $2 into a list
# 1  
Old 08-09-2010
greping $2 into a list

Hi
When I run this command:
Code:
lsuser -a auditclasses ALL

I got:
Code:
user1 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user2 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user3 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user4 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
.
.

so, I need a script to show ONLY if a "auditclasses" entry is different from the "general,objects,cron,files,rbac,audit,lvm,aixpert" string.

NOTES:
- AIX 5.x and 6.1
- ksh
- lot of users in lsuser output.

thanks
regards
Israel.
# 2  
Old 08-09-2010
Code:
lsuser -a auditclasses ALL | grep -v "auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert"

# 3  
Old 08-09-2010
Code:
 
# lsuser -a auditclasses ALL 
user1 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user2 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user3 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user4 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert
user5 auditclasses=generalXX,objects,cron,files,rbac,audit,lvm,aixpert
.
.


Code:
 
# ./justdoit
user5 auditclasses=generalXX,objects,cron,files,rbac,audit,lvm,aixpert

Code:
#!/bin/ksh
lsuser -a auditclasses ALL | while IFS= read -r var
  do
    if [[ $(echo ${var}|sed 's/.*auditclasses=\(.*\)/\1/') != "general,objects,cron,files,rbac,audit,lvm,aixpert" ]]
       then
         echo "$var"
    fi
  done

# 4  
Old 08-09-2010
That's it

thanks ygemici
# 5  
Old 08-09-2010
As far as I recall the Korn shell on AIX is ksh93 - so the following should work:
Code:
lsuser -a auditclasses ALL |
while read user ac
do
   [[ ${ac} == auditclasses=* && ${ac} != "auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert" ]] && echo ${ac}
done

# 6  
Old 08-09-2010
Hi fpmurphy

/usr/bin/ksh93 is not the default korn shell for AIX. /usr/bin/ksh is. but I can use ksh93 without problems.. thanks for your reply.

regards
Israel.
# 7  
Old 08-10-2010
i think this would work.. correct me if ive gone wrong.

Code:
#! /usr/bin/perl

use strict;
use warnings;

my $command = 'lsuser -a auditclasses ALL';

open(my $FH,"-|",$command) or die "Error $! executing $command\n";

while(<$FH>)
{
   if(!/^.*auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert.*/)
      {
      print;
      }
}
close $FH;

 # return value automatically stored in $?
   if($? != 0)
   {
       print "Something went wrong\n";
    }


Previous Thread | Next Thread
Test Your Knowledge in Computers #974
Difficulty: Medium
Version 1.0 of the Linux kernel was released on 14 March 1994.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Qn on awk greping values

Hello Experts, I was trying to awk out some data out of a text file. Below is a sample file which I have xxx ***Wed Jun 28 18:00:59 CDT 2015 avg-cpu: %user %nice %system %iowait %steal %idle 17.10 0.00 4.56 2.86 0.00 75.48 Device: rrqm/s wrqm/s ... (2 Replies)
Discussion started by: DevAnand
2 Replies

2. Shell Programming and Scripting

Greping frequency for list of phrases is a separate file

Dear All I have a big set of data which I would like to summerize to have a better sense of it the problem is like this ... I have more than 200 files each related to a person which includes different sentences with specific elements (files in a directory) e.g. mark (one file in the directory)... (9 Replies)
Discussion started by: A-V
9 Replies

3. Shell Programming and Scripting

Greping the string from a log

Hi Folks, I am searching something in multiple logs , actually an even ocuurs which get recorded in logs with a special word so rite now I am opening an individual log in vi and then searching it but total in the directory there are such 15 logs and it is very difficult to go one by one so... (1 Reply)
Discussion started by: punpun66
1 Replies

4. Shell Programming and Scripting

need help in greping

Hi, i have to find a string in a file and positin of the string in the file would come in some particular interval. let's say file is 1-1000 lines and string is in from 200-300line. could any one suggest me how to get make the grep search for the string in that particular portion of the... (4 Replies)
Discussion started by: tarakant
4 Replies

5. Shell Programming and Scripting

Greping in between two different lines.

I know you could use the grep "something" -A200 flag to get all the lines past your pattern. Is there a way to get all the lines in between two patterns? The -a flag will not work since all lines in between the two patterns don't have a constant number. (4 Replies)
Discussion started by: jwillis0720
4 Replies

6. Shell Programming and Scripting

greping ip address

I have this line BTSRTRGRP-448-1-1 10.162.141.118/255.255.255.254 - I need to print only the IPADDRESS and not the subnet mask. If i use cut -c30-43 I get the ipaddress, where as in some cases if the last octet is of single digit (10.162.141.8/255.255.255.254) it... (2 Replies)
Discussion started by: miltonrods
2 Replies

7. Shell Programming and Scripting

need help in greping

i have a ksh script : #!/bin/ksh TZ=`date +%Z`+24 ;a=`date +%Y-%m-%d` b=`date +"%H:%M:%S"` cd /ednadtu3/u01/pipe/logs for i in Archiver1.log do cat $i | grep $a | grep $b >> /ednadtu3/u01/pipe/naveed/Insert_Date.txt done... (4 Replies)
Discussion started by: ali560045
4 Replies

8. Shell Programming and Scripting

Greping certain lines

One of my outout is like this as shown below. How can I grep only the lines after the line "Affected files ...". No of lines after the line "Affected files ..." may vary. $ cat file_A Change 149133 by csaha@test_depo_csaha on 2006/02/08 01:40:57 *pending* This is to test change #... (5 Replies)
Discussion started by: csaha
5 Replies

9. UNIX for Dummies Questions & Answers

GREPing for Nulls

I just had a filesystem / file corruption issue on my HSP's server due to disk capacity limits and fileswapping. I discovered that certain files got corrupted when fileswapping was not successful and they ended up with a string of control characters, or what I believe to be nulls, in them. Does... (4 Replies)
Discussion started by: Dr. DOT
4 Replies

10. UNIX for Dummies Questions & Answers

Help with greping a field

Hi, Suppose I have a file as below and I just want the field Invoice Number from this file , How can I do it. /home/arbor>cat PH0034090202314800030IM-001 0Yp825XMilperra NSW 1891 189110H14V1Sp2871Yp300X Customer Service : 0000-368-81118H6.5V0Sp3130Yp50X ... (7 Replies)
Discussion started by: rooh
7 Replies

Featured Tech Videos