Find a sub chain in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a sub chain in a file
# 1  
Old 08-03-2009
Find a sub chain in a file

Hello,

I have a logfile from which i would to extract date and login information.
(the goal is to find the inactive users).
To extract the date, no problem.
To extract the login, i'm stuck.

I first extract lines which contains the logging-in information, i obtain different lines.
Here are 2 lines from the log:
Code:
2009/07/30_00:02:10.30      COM_srv.2   ::S::   xxxxxxxx:xxxxxxxx:xxxxxxxx(RULE:xxx) (FROM:_INBOX.xxxxxx.xxxxxxx.xxxxx) (TO:QUERYSRVdefault) MSG= >>L FwExecuteServerSideRuleTxn msgTag=_INBOX.xxxxxxx.xxxxxxx.xx name=xxxxxxxx attributes={ { class=xxxxxxxxx { class=A1 "PARAMETER" } {class=A1 "VALUE" } } { "USERID" "BV26" } { "PASSWORD" "xxxxxxxx" } { "KEYINFO" "xxxxxxxxxxx" } { "CHKPASSWD" "T" } { "TUNNELID" "" } { "xxx" "xxxxxxx_xxxxxx_xxxxxxxxx" } }
2009/07/30_00:02:16.31      COMM_srv.2   ::R::   xxxxxxxxx:xxxxxxx:xxxxxx (RULE:xxx) (FROM:xx) (TO:xx) MSG= {DATA=">>L xxxxxxxxxxx xxx xxxxx=QUERYSRVdefault name=xxxxxxxxxx attributes={ { class=xxxxxxx { class=A1 "PARAMETER" } { class=A1 "VALUE" } } { "USERID" "BG77" } { "PASSWORD" "xxxxxxxxx" }{ "KEYINFO" "xxxxxxxxxxx" } { "CHKPASSWD" "T" } { "TUNNELID" "" } { "TID" "xxxxxxxxx_xxxxxx_xxxxxxxxx" } }"}

How could i extract the login value (the field after "USERID", BV26 ou BG77 in may example) in csh ?
I've tried different awk but my poor knowledge on it didn't help me.

Thank in advance.

Last edited by Yogesh Sawant; 08-03-2009 at 10:09 AM.. Reason: added code tags
# 2  
Old 08-03-2009
using Perl:
Code:
perl -nl -e 'if (m/\"USERID\"\s\"(.*?)\"/) { print $1; }' logfile

# 3  
Old 08-03-2009
Thanks Yogesh, you're the best Smilie

That's exactly what i wanted.

Have a good day !
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Logging Aggregator and Reporting For a Chain

Hello, I'am lerning Powershell and have this task. can anyone help? Imagine a fitness studio chain that operates different studios in Munich. Every studio has been given a Windows server that operates the entry of studio clients via a key-card (NFC) and it also operates the cashier at the bar... (1 Reply)
Discussion started by: akotb
1 Replies

2. UNIX for Advanced & Expert Users

Editing iptables rules with custom chain

Hello, I have iptables service running on my CentOS5 server. It has approx 50 rules right now. The problem I am facing now is as follows - I have to define a new chain in the filter table, say DOS_RULES & add all rules in this chain starting from index number 15 in the filter table. ... (1 Reply)
Discussion started by: BhushanPathak
1 Replies

3. Ubuntu

forward packet from input chain to output

Hi, I receive a packet at input chain of iptables in filter table. How can i forward that same packet exactly to the output chain of the iptables in filter table. I need this help desperately. Thanks. (0 Replies)
Discussion started by: arsipk
0 Replies

4. UNIX for Advanced & Expert Users

[SOLVED] No INPUT chain on nat table in iptables

Hello, I'm having problem with an iptables rule. It seems that on one of two systems on the nat table, the INPUT chain doesn't exist for some strange reason. I get the error below: # iptables -t nat -A INPUT -j ACCEPT iptables: No chain/target/match by that name. Here is my kernel on... (0 Replies)
Discussion started by: Narnie
0 Replies

5. Shell Programming and Scripting

[solved] Killing 3rd command in ssh chain

Hi All, Noob question here... How do I kill the 3rd command in this ssh chain effectively? # ssh -t -t 10.80.0.5 'ssh 10.80.0.6 | /var/tmp/some_script' The "/var/tmp/some_script" contains: ssh 10.80.0.81 'echo "Hello World!!!!" >> /tmp/sample.txt'The problem is that once the sample.txt... (2 Replies)
Discussion started by: NYG71
2 Replies

6. UNIX for Dummies Questions & Answers

Is it possible to extract a certificate chain?

Hi all! I wanted to look at the key length of a certificate chain we have. When I do the conventional export command using keytool I will only get the end user cert. keytool -export -alias aliasname -file filename.cer -keystore keystorename The above code will only give me the end user... (2 Replies)
Discussion started by: Keepcase
2 Replies

7. UNIX for Advanced & Expert Users

Building a ppc476 enabled GCC cross compiler and tool chain

Building a ppc476 enabled GCC cross compiler and tool chain Hello, I am trying to build a cross GCC compiler for PPC476. I applied all the relevant patches. Cross compiler build was successful. When i try to compile the source code using the cross compiler i am getting the below error... (1 Reply)
Discussion started by: raghuhb
1 Replies

8. Shell Programming and Scripting

How to chain some commands together

Hey, I am fiddling with a little script to kill a certain program if it freezes. Basically I want to do something like this: ps -A | grep firefox-bin | read -d ' ' pid kill $pid The problem lies when I pipe the output of grep into read. That part does not seem to work the way I want... (4 Replies)
Discussion started by: kermit
4 Replies
Login or Register to Ask a Question