LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2012, 04:36 AM   #1
dcsmayei
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Rep: Reputation: Disabled
how to extract a 2-line pattern from a file using awk, grep, etc.


1. I want to identify usernames with the same password which is a security/audit issue.
2. The audit script output tests all such connections to the server database having the same password.
3. I need to extract only the usernames that connect successfully so that these passwords can be addressed. I know how to change passwords

4. Here is a sample of the huge output file:
SQL> connect AA/AA;
Connected.
SQL> connect B4B/B4B;
ORA-28000: the account is locked
Warning: You are no longer connected to ORACLE.
SQL> connect CCg/CCg;
ORA-01017: invalid username/password; logon denied
SQL> connect Dee/Dee;
Connected.
SQL> connect eR/eR;
ORA-28000: the account is locked
Warning: You are no longer connected to ORACLE.
SQL> connect Fdw2/Fwd2;
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> connect gAMw/gAMw;
Connected.

5. I would like an output file similar to this after pattern searching (i.e. only the connected usernames):
SQL> connect AA/AA;
Connected.
SQL> connect Dee/Dee;
Connected.
SQL> connect gAMw/gAMw;
Connected.

NB: the search should have nothing to do with usernames starting with an alphabet.

Much obliged,
Waiting in anticipation!
 
Old 06-08-2012, 04:46 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
You can use: awk ' BEGIN { RS="SQL>" } ... ' and you will get the info in one line. You can use /Connected/ to find successful logins....
 
Old 06-08-2012, 05:00 AM   #3
dcsmayei
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thx Pan64.
Apologies I'm a beginner with awk.

Kindly explain to me how to just get the connected usernames from the output file.
By that I mean, after awk or whatever command or script, I get an output file as follows or similar:
SQL> connect AA/AA;
SQL> connect Dee/Dee;
SQL> connect gAMw/gAMw;

Tx
 
Old 06-08-2012, 05:04 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
something like this:
Code:
awk ' BEGIN { RS="SQL>" }
      /Connected/ { print "SQL> connect " $2 } ' inputfile




_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
 
Old 06-08-2012, 05:19 AM   #5
dcsmayei
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
tx for the expanded command.

I now get the following output:
SQL> connect connect
SQL> connect Connected.
SQL> connect connect
SQL> connect connect
SQL> connect connect
SQL> connect Connected.
SQL> connect connect

instead of the three connected usernames as in my first posting?

pls help!
 
Old 06-08-2012, 06:01 AM   #6
dcsmayei
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
i guess nobody knows the answer to my question!!

or did I not not explain it well enough??

hello Q&A forum????
 
Old 06-08-2012, 07:00 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
it works fine for me, so probably you mistyped something or you have a different environment. Try to replace $2 with $1 or $3 and start again....






_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
 
1 members found this post helpful.
Old 06-08-2012, 07:51 AM   #8
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware
Posts: 89

Rep: Reputation: 24
From grep's man page:
Code:
   Context Line Control
       -A NUM, --after-context=NUM
              Print  NUM  lines of trailing context after matching lines.  Places a line containing a group
              separator (--) between contiguous groups of matches.  With the -o or --only-matching  option,
              this has no effect and a warning is given.

       -B NUM, --before-context=NUM
              Print  NUM  lines of leading context before matching lines.  Places a line containing a group
              separator (--) between contiguous groups of matches.  With the -o or --only-matching  option,
              this has no effect and a warning is given.
So just grep -B1 Connected <FILENAME> to get your results and please, restrain yourself from posts like http://www.linuxquestions.org/questi...9/#post4698608 some of us find it offensive. Especially when you didn't look at the documentation. Have a great day!
 
Old 06-08-2012, 08:51 AM   #9
dcsmayei
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank u guys! $3 worked!
 
Old 06-09-2012, 09:32 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by dcsmayei View Post
i guess nobody knows the answer to my question!!

or did I not not explain it well enough??

hello Q&A forum????
May I ask what is the reason of such a rude comment? You posted this only 42 minutes after your last feedback. Maybe your issue was so urgent that you feel justified in addressing LQ members like that?!? Please, refrain from this behavior in the future and try to apply a bit of netiquette.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to print a line if i dont find the pattern using grep.! how is this possible? ameylimaye Linux - Newbie 4 09-28-2011 12:57 PM
How to search a pattern only first line using awk debianD Programming 8 08-02-2011 09:19 PM
replace a pattern with a line using sed/awk lokeshn05 Linux - Newbie 3 05-06-2009 04:01 PM
Need ideas on how to grep for pattern using awk rahulbgl Linux - Newbie 4 03-05-2007 04:07 PM
Grep pattern first line of a file ericcarlson Linux - Newbie 11 07-20-2004 11:51 AM


All times are GMT -5. The time now is 02:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration