LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2012, 04:53 AM   #1
drd0spt
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Rep: Reputation: Disabled
Grep \ Shell Script \ Parsing


Hi i know there is some other threads about grep and parsing but i tryed most of the other ways describe on the other questions and didnt work for me, i would like to parse a openssl log to a .csv and by that make the usual ; to pars the columns .

output to parse :

Signature Algorithm: sha1WithRSAEncryption

Issuer: C=PT, L=Jersey, O=UFO - UFO Solutions,
CN=UFO Software ROOT Primary CA/emailAddress=ufo@wtf.us

Validity
Not Before: Jan 24 11:10:13 2011 GMT
Not After : Jan 21 11:10:13 2021 GMT

Subject: C=US, L=Jersey, O=UFO - UFO Solutions,OU=CER, CN=UFO PSS Intermediate CA/emailAddress=ufo@wtf.us

Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (2048 bit)

I want to parse the data in front of "Signature Algorithm :" , the dates in "Not Before:" and "Not After", and the values in front of "C=", "L=" , "CN=", "O=" , "OU= ", "EmaiAddress=" . And finally the Public key algorithm : , and RSA public key value the " (2048 bit) "

to the >> example.csv

The desired output would be :

sha1WithRSAEncryption, Jan 24 11:10:13 2011 GMT, Jan 21 11:10:13 2021 GMT, PT, Jersey, UFO, etc.


thanks in advance.

Last edited by drd0spt; 09-27-2012 at 12:01 PM. Reason: clear wanted result
 
Old 09-27-2012, 05:10 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,260

Rep: Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321
Search for a download - why reinvent the wheel?

For something as involved as you are asking, grep & bash is a bit cumbersome. There is awk, and sed which might thrash it out better for you.

That said, if you do go at this, there is an option for you to use perl's regular expression stuff which is a bit tidier and more definite than posix, in my experience.
man perlre is your friend
 
Old 09-27-2012, 05:13 AM   #3
drd0spt
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
I have this :

Quote:
#!/bin/bash
#v.0.1

wrd=$(grep -oP '(?<==)\w*' ex.txt)


for w in $wrd
do
$w";" >> resultado.csv
done
But that just dont parse the ":" values or in thi case the dates

Last edited by drd0spt; 09-27-2012 at 05:15 AM.
 
Old 09-27-2012, 05:24 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
drd*;

I think you mean the data AFTER the keywords---for example, when it finds "Signature Algorithm:", it would return: "sha1WithRSAEncryption"

To be clear, please post the desired output I'm guessing that it would be:
"sha1WithRSAEncryption, Jan 24 11:10:13 2011 GMT, Jan 21 11:10:13 2021 GMT, etc."
 
Old 09-27-2012, 05:29 AM   #5
drd0spt
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
That is exactly what i want pixellany

the desired output would be :

"sha1WithRSAEncryption, Jan 24 11:10:13 2011 GMT, Jan 21 11:10:13 2021 GMT, PT, Jersey, UFO, etc."
 
Old 09-28-2012, 04:34 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Here is a start (written as a script):
Code:
#!/bin/bash
sed -n -r -e 's/Signature Algorithm: (.*)$/\1/p' \
-e 's/Not Before: (.*)$/\1/p' \
-e 's/Not After: (.*)$/\1/p' \
-e '/Issuer:/s/.*C=([^,]*),.*L=([^,]*),.*O=([^-]*)-.*/\1 \2 \3/p' < filename
It does not yet pick up every item, and they are not yet in order.

I am QUITE SURE there is an easier way to do this......
 
  


Reply



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
Problem with shell script when parsing and forwarding email forward Programming 1 06-21-2009 12:32 PM
LXer: Parsing arguments for your shell script LXer Syndicated Linux News 0 07-18-2007 03:17 AM
(shell script) string parsing kuru Programming 4 09-12-2005 07:59 PM
Script File: Parsing command sent to shell cheema Programming 1 07-01-2005 12:54 PM
File Parsing using a Shell Script yasir15 Programming 5 08-22-2003 12:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:15 PM.

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
Open Source Consulting | Domain Registration