LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-27-2015, 05:24 PM   #1
dr.x
Member
 
Registered: Jan 2013
Posts: 167

Rep: Reputation: Disabled
how to cut linux content that start with something from a file ?


Hi guys

say i have a file like below :
[root@localhost keys]# cat viber1.crt
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=US, ST=CA, L=San, O=Fort, OU=Fortx, CN=Fortxx/name=Forty/emailAddress=info@viberbd.com
Validity
Not Before: Nov 27 21:30:45 2015 GMT
Not After : Nov 24 21:30:45 2025 GMT
Subject: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=changeme/name=changeme/emailAddress=mail@host.domain
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:dd:b5:23:d8:51:85:e0:55:57:47:54:87:54:54:
37:31:6e:db:a2:03:65:ac:d6:e0:c2:b9:b3:f8:d6:
c3:c1:14:33:b1:68:08:d1:d2:96:a5:9b:4a:16:d7:
6a:fd:e3:e4:60:87:a2:f2:86:b0:8d:a4:52:1a:e2:
fe:72:18:95:c1:a4:e9:ef:2c:3a:39:49:15:7e:e8:
d4:a9:fc:74:0e:60:86:0c:5f:16:da:a1:e9:13:65:
82:4c:20:7a:2f:e8:c7:fd:b1:21:cf:33:8b:89:eb:
b1:7b:fa:8c:f0:43:28:1f:63:5e:2d:28:00:9e:19:
64:8a:c1:8f:ba:64:a1:bb:09
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
Easy-RSA Generated Certificate
X509v3 Subject Key Identifier:
89:46:2B:22:82:93:7D:30:A8:3E:99:20:8B:57:7E:41:5A:CB:40:2A
X509v3 Authority Key Identifier:
keyid:E1:1D:31:03:B6:CC:C5:A0:07:09:4A:E4:43:8A:19:69:50:F0:0B:F7
DirName:/C=US/ST=CA/L=San/O=Fort/OU=Fortx/CN=Fortxx/name=Forty/emailAddress=info@viberbd.com
serial:EC:1C:28:C5:8F:EB:05:8E

X509v3 Extended Key Usage:
TLS Web Client Authentication
X509v3 Key Usage:
Digital Signature
Signature Algorithm: sha1WithRSAEncryption
aa:7f:37:4e:72:e9:2d:d6:cf:24:e3:1c:69:bf:c3:9b:38:33:
bc:63:07:fa:d1:96:a4:ea:1b:3e:7c:00:90:57:9d:74:87:59:
85:dd:ed:4c:30:fa:89:15:03:c1:9c:02:e0:59:ac:1a:82:b1:
9e:b0:f7:5b:dc:ed:12:8f:37:01:79:82:7a:1e:48:50:77:f2:
0f:b4:46:93:33:9f:12:c1:ec:8a:2f:aa:5b:84:00:6c:56:aa:
27:b9:2b:ca:59:84:fb:36:ba:68:4c:61:39:26:b0:c2:e5:37:
7f:8f:d5:77:f6:76:51:73:1e:22:9d:68:fd:85:5b:e7:12:e8:
32:2d
-----BEGIN CERTIFICATE-----
MIID5zCCA1CgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx
CzAJBgNVBAgTAkNBMQwwCgYDVQQHEwNTYW4xDTALBgNVBAoTBEZvcnQxDjAMBgNV
BAsTBUZvcnR4MQ8wDQYDVQQDEwZGb3J0eHgxDjAMBgNVBCkTBUZvcnR5MSAwHgYJ
KoZIhvcNAQkBFhFpbmZvQHZpYmVyYmQuY29tIDAeFw0xNTExMjcyMTMwNDVaFw0y
NTExMjQyMTMwNDVaMIGiMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTATBgNV
BAcTDFNhbkZyYW5jaXNjbzEVMBMGA1UEChMMRm9ydC1GdW5zdG9uMREwDwYDVQQL
EwhjaGFuZ2VtZTERMA8GA1UEAxMIY2hhbmdlbWUxETAPBgNVBCkTCGNoYW5nZW1l
MR8wHQYJKoZIhvcNAQkBFhBtYWlsQGhvc3QuZG9tYWluMIGfMA0GCSqGSIb3DQEB
AQUAA4GNADCBiQKBgQDdtSPYUYXgVVdHVIdUVDcxbtuiA2Ws1uDCubP41sPBFDOx
aAjR0palm0oW12r94+Rgh6LyhrCNpFIa4v5yGJXBpOnvLDo5SRV+6NSp/HQOYIYM
XxbaoekTZYJMIHov6Mf9sSHPM4uJ67F7+ozwQygfY14tKACeGWSKwY+6ZKG7CQID
AQABo4IBQTCCAT0wCQYDVR0TBAIwADAtBglghkgBhvhCAQ0EIBYeRWFzeS1SU0Eg
R2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBSJRisigpN9MKg+mSCLV35B
WstAKjCBvwYDVR0jBIG3MIG0gBThHTEDtszFoAcJSuRDihlpUPAL96GBkKSBjTCB
ijELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMQwwCgYDVQQHEwNTYW4xDTALBgNV
BAoTBEZvcnQxDjAMBgNVBAsTBUZvcnR4MQ8wDQYDVQQDEwZGb3J0eHgxDjAMBgNV
BCkTBUZvcnR5MSAwHgYJKoZIhvcNAQkBFhFpbmZvQHZpYmVyYmQuY29tIIIJAOwc
KMWP6wWOMBMGA1UdJQQMMAoGCCsGAQUFBwMCMAsGA1UdDwQEAwIHgDANBgkqhkiG
9w0BAQUFAAOBgQCqfzdOcukt1s8k4xxpv8ObODO8Ywf60Zak6hs+fACQV510h1mF
3e1MMPqJFQPBnALgWawagrGesPdb3O0SjzcBeYJ6HkhQd/IPtEaTM58SweyKL6pb
hABsVqonuSvKWYT7NrpoTGE5JrDC5Td/j9V39nZRcx4inWj9hVvnEugyLQ==
-----END CERTIFICATE-----




all i need is only the section below :

-----BEGIN CERTIFICATE-----
MIID5zCCA1CgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx
CzAJBgNVBAgTAkNBMQwwCgYDVQQHEwNTYW4xDTALBgNVBAoTBEZvcnQxDjAMBgNV
BA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dOcukt1s8k4xxpv8ObODO8Ywf60Zak6hs+fACQV510h1mF
3e1MMPqJFQPBnALgWawagrGesPdb3O0SjzcBeYJ6HkhQd/IPtEaTM58SweyKL6pb
hABsVqonuSvKWYT7NrpoTGE5JrDC5Td/j9V39nZRcx4inWj9hVvnEugyLQ==
-----END CERTIFICATE-----

the question here is , how to setup a rule on bash to cut the info that start with "-----BEGIN CERTIFICATE-----" and end with "-----END CERTIFICATE-----"

and send it to other file ??

thank you
 
Old 11-27-2015, 10:49 PM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 2,047

Rep: Reputation: 436Reputation: 436Reputation: 436Reputation: 436Reputation: 436
For example with sed. You can tell it to only print lines between these two strings:

Code:
sed -n '/^-----BEGIN CERTIFICATE/,/^-----END CERTIFICATE/p' viber1.crt > otherfile
The -n option tells sed to print nothing except if explicitly asked.
The two regular expressions mark the beginning and end of a range.
The p command prints each line in that range.
Due to the -n option, no other line is printed.
The apostrophes are not needed in this case, but regular expressions often include characters with a special meaning for the shell, so it's good practice to always use them.

You can also use awk and perhaps other commands from the UNIX text processing toolkit.

Last edited by berndbausch; 11-27-2015 at 10:51 PM.
 
1 members found this post helpful.
Old 11-27-2015, 11:36 PM   #3
dr.x
Member
 
Registered: Jan 2013
Posts: 167

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
For example with sed. You can tell it to only print lines between these two strings:

Code:
sed -n '/^-----BEGIN CERTIFICATE/,/^-----END CERTIFICATE/p' viber1.crt > otherfile
The -n option tells sed to print nothing except if explicitly asked.
The two regular expressions mark the beginning and end of a range.
The p command prints each line in that range.
Due to the -n option, no other line is printed.
The apostrophes are not needed in this case, but regular expressions often include characters with a special meaning for the shell, so it's good practice to always use them.

You can also use awk and perhaps other commands from the UNIX text processing toolkit.
Thank you Thank you
Thank you Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
 
Old 11-28-2015, 12:31 AM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 2,047

Rep: Reputation: 436Reputation: 436Reputation: 436Reputation: 436Reputation: 436
Quote:
Originally Posted by dr.x View Post
Thank you Thank you
Thank you Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
I see you also learned how to program loops
 
1 members found this post helpful.
Old 11-28-2015, 02:39 AM   #5
dr.x
Member
 
Registered: Jan 2013
Posts: 167

Original Poster
Rep: Reputation: Disabled
You were awesome
 
Old 11-28-2015, 09:12 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
Heh ... when given the chance, computer programmers always make things easy on themselves. Such as by, for example, "bracketing" certificate information with boundary-markers that are easy to grep.
 
  


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
dolphin mess start typing in file name or requested content and search begins...non landonmkelsey Linux - Software 0 11-29-2011 06:39 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
Intel to cut Linux out of the content market Garda Linux - News 5 09-14-2005 07:07 PM
Intel to cut Linux out of the content market! :( Ausar Linux - News 20 08-08-2005 08:59 PM
Firefox won't start: file /content/browser.xul cannot be found nimcha Linux - Software 2 05-20-2004 01:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:48 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