Sponsored Content
Top Forums Shell Programming and Scripting Search for a text between two strings in a file using regex Post 303043157 by mohtashims on Monday 20th of January 2020 06:50:35 AM
Old 01-20-2020
Search for a text between two strings in a file using regex

Here is my sample file data:

Quote:
##
## SSL Virtual Host Context

SSLInsecureRenegotiation Off

Seconds before invalid OCSP responses are expired from the cache

<VirtualHost _default_:443>
SSLInsecureRenegotiation Off
RewriteOptions Inherit
SSLInsecureRenegotiation Off
RewriteOptions Inherit

# General setup for the virtual host
DocumentRoot "/web/htdocs"
ServerName www.example.com:443
ServerAdmin you@example.com
ErrorLog "|/web/bin/rotatelogs /web/logs/sslerror_log.%Y-%m-%d 86400 combined"
TransferLog "/web/logs/access_log"

# SSL Engine Switch:
SSLEngine on

SSLCertificateFile "/web/conf/server.crt"

# ECC keys, when in use, can also be configured in parallel
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/web/cgi-bin">
AllowOverrideList None

# SSLInsecureRenegotiation Off

</Directory>

CustomLog "/web/logs/ssl_request_log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

SSLInsecureRenegotiation On
# BEGIN ANSIBLE MANAGED BLOCK
<FilesMatch "^.*\.(css|html?|js|pdf|txt|xml|xsl|gif|ico|jpe?g|png)$">
Require all granted
</FilesMatch>
# END ANSIBLE MANAGED BLOCK
</VirtualHost>
My requirement is to have a regex expression that is able to search for visible starting string "SSLInsecureRenegotiation Off" between strings "<VirtualHost " and "</VirtualHost>".

In the sample data two lines should be matched.

Below is what I tried but it does not match the two lines within the Virtual Tags.

Code:
(?<=<VirtualHost ).*^[^#]*SSLInsecureRenegotiation.*Off.*(?=</VirtualHost>)

Can you please suggest how ?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search multiple strings in a file

Hi All, I want to search all the ksh scripts that has following details. 1. Search for "exit 0" 2. Search for "sqlldr" or sqlplus" 3. In the above files i want to search for all the script that has no "case" in it. Please advice. Thanks, Deep (2 Replies)
Discussion started by: deepakpv
2 Replies

2. Shell Programming and Scripting

search file between last occurence of 2 strings

I need to extract the last block of /== START OF SQLPLUS ==/ and /== END OF SQLPLUS ==/. The logifle is written to several times in a day using >> to append. I need a solution using grep/sed. logfile looks like this START OF LOGFILE /== START OF SQLPLUS ==/ ERROR /== END OF SQLPLUS... (5 Replies)
Discussion started by: hanton
5 Replies

3. Shell Programming and Scripting

Search complicated strings on file

Can someone help me? I been figuring out how I can search and extract a complicated search string from a file. The whole string is delimited by a period. And the file where I'm searching is composed of differnt string such as that. For example, I have this search string: and I have a file... (3 Replies)
Discussion started by: Orbix
3 Replies

4. Shell Programming and Scripting

Search multiple Strings in a File

Hi I want to search multiple strings in a file . But the search should start with "From" Keyword and end with before "Where" keyword. Please suggest me. Thanks (2 Replies)
Discussion started by: sboss
2 Replies

5. Shell Programming and Scripting

Best Alternative to Search Text strings in directory

Hi All, We have a file "Customers.lst". It contains list of all the Customers. There is directory which has number of text files and each file containing name of defaulter customers. We want to search for all the customers available in "Customers.lst" file against the list of files... (8 Replies)
Discussion started by: arunorcl
8 Replies

6. Shell Programming and Scripting

Search replace strings between single quotes in a text file

Hi There... I need to serach and replace a strings in a text file. My file has; books.amazon='Let me read' and the output needed is books.amazon=NONFOUND pls if anybody know this can be done in script sed or awk.. i have a list of different strings to be repced by NONFOUND.... (7 Replies)
Discussion started by: Hiano
7 Replies

7. Shell Programming and Scripting

Search strings from array in second file

I have a file search_strings.txt filled with search strings which have a blank in between and look like this: S. g. Erh. o. J. v. d. Chijs g. Ehr.I would like to search the strings in the second given Textfile.txt and it shall return the column number. Can anybody help with the correct... (3 Replies)
Discussion started by: sdf
3 Replies

8. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

9. UNIX for Beginners Questions & Answers

Using strings in one file as regex to search field of another file

I have a data file, file1.txt, such as the following: 1,2 "TWRTW", "TWRH/" 1,2 "JHGH", "HGJ 1,2 "JWMM", "JWMM" 1,2 "W", "W" 1,2 "LJLH", "LJLH/" 1,3 "W", "W" 1,3 "HJH", "HJJ I have another file, file2.txt, that contains... (3 Replies)
Discussion started by: jvoot
3 Replies

10. Shell Programming and Scripting

Need grep regex to extract multiline text between two strings

I have a file conatining the below: --- 10.9.16.116: /tmp/5835113081224811756.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb /tmp/4603745991442278706.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb 10.9.14.126: /tmp/conf/extra/httpd-ssl.conf: hash:... (1 Reply)
Discussion started by: mohtashims
1 Replies
PERLANET(1p)						User Contributed Perl Documentation					      PERLANET(1p)

NAME
perlanet - command line interface to Perlanet.pm SYNOPSIS
$ perlanet Or $ perlanet config_file DESCRIPTION
"perlanet" is a command line program for aggregating web feeds (both Atom and RSS) and publishing a new web page and a new web feed containing the results of that aggregation. COMMAND LINE ARGUMENTS
"perlanet" takes one optional command line argument, which is the name of a configuration file to use. If no filename is given then the program looks for a file called "perlanetrc" in the current directory. CONFIGURATION FILE
"perlanet" requires a configuration file which contains details of which feeds to aggregate and what to do with the results of the aggregation. By default, "perlanet" looks for a file called "perlanetrc" in the current directory, but this name can be overridden by passing the name of a different file when calling the program. The configuration file is in YAML format. YAML is a simple text-based file format. See <http://yaml.org/> for further details. Configuration Options The configuration file can contain the following options. title The title of the resulting page and web feed. This option is mandatory. description The description of the resulting page and web feed. This option is mandatory. url A URL which will be associated with the resulting page and web feed. This will usually be the address where the web page will be published. This option is mandatory. author The name and email address of the author of the aggregated content. This item has two sub-items - one each for the name and email address. This option is mandatory. agent This optional entry defines the agent string that perlanet will use when requesting data from web sites. It's the name of the program that site owners will see in their web site access logs. Although it is optional, it is strongly recommended that you give a value for this configuration option and that the value you use includes contact details so that web site owners can get in touch with you if they have any concerns about your use of their site. entries The maximum number of entries to include in the aggregated content. This option is mandatory. entries_per_feed The "entries" value above defines the total number of entries in the aggregated output feed. The <entries_per_feed> value defines the number of entries to take from each of your source feeds. For example, if this is set to 1 then there will only be one entry from each feed in your output. If this value is 0 (or missing) then all values from all source feeds are used. opml The system can optionally create an OPML file containing details of the feeds which are being aggregated. This optional option controls whether or not this file is created. If it exists, it should be the name of the OPML file to be created. If an OPML file is being created, then the "feeds" options (described below) will all require a "web" sub-option. page This mandatory option contains the details of the web page to be created. There are two sub-options - "file" gives the name of the file to be created and "template" gives the name of a Template Toolkit template which will be processed in order to create this file. See the section "Output Template" for more details on this template, and the web site <http://tt2.org/> for more information about the Template Toolkit. feed This mandatory option contains the details of the web feed to be created. There are two sub-options - "file" gives the name of the file to be created and "format" gives the format of the output (currently 'Atom' or 'RSS'). cache_dir This if you give a directory name in this option then perlanet will use the cache facility of URI::Fetch. This means that web feeds will only be downloaded when they change. feeds This mandatory option gives details of the web feeds to be aggregated. Each item on the list has one mandatory sub-option and two optional sub-options. The mandatory sub-option is "url" which gives the URL of the feed. The optional sub-option "title" gives a title which will be prepended to all of the entry titles taken from that feed. If no title is given, then the title will be taken from the feed title. The optional "web" sub-option gives a web site URL associated with the feed (often the address of the web site that the feed comes from). This can be used to create a list of the aggregated sites. The "web" sub-option becomes mandatory if you are creating an OPML file. Example Configuration File title: planet test description: A Test Planet url: http://planet.example.com/ author: name: Dave Cross email: dave@dave.org.uk entries: 20 opml: opml.xml page: file: index.html template: index.tt feed: file: atom.xml format: Atom cache_dir: /tmp/feeds feeds: - url: http://blog.dave.org.uk/atom.xml title: Dave's Blog web: http://blog.dave.org.uk/ - url: http://use.perl.org/~davorg/journal/rss title: Dave's use.perl Journal web: http://use.perl.org/~davorg/journal/ - url: http://www.oreillynet.com/pub/feed/31?au=2607 title: Dave on O'Reillynet web: http://www.oreillynet.com/pub/au/2607 Output Template The web page is created from a Template Toolkit template. This template is passed two variables. feed This is the XML::Feed object which has been used to create the aggregated feed. See the XML::Feed documentation for details of the data that is held in this object. cfg This is the contents of the configuration file, converted to a (nested) Perl hash. Example Output Template This is a simple template which uses the "feed" variable to display details of the aggregated feeds. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>[% feed.title %]</title> </head> <body> <h1>[% feed.title | html %]</h1> <p>[% feed.description | html %]</p> [% FOREACH entry IN feed.entries %] <h2><a href="[% entry.link | url | html %]">[% entry.title | html %]</h2></a> [% entry.content.body %] [% IF entry.author OR entry.issued %] <p>Published[% IF entry.author %] by [% entry.author | html; END %] [% IF entry.issued %] on [% entry.issued | html; END %]</p> [% END %] [% END %] <hr /> <address>[% feed.author | html %] / [% feed.modified | html %]</address> </body> </html> In the future, the Perlanet wiki at <http://wiki.github.com/davorg/perlanet> will contain a cookbook of useful ideas to include in the output template. SUPPORT
There is a mailing list which acts as both a place for developers to talk about maintaining and improving Perlanet and also for users to get support. You can sign up to this list at http://lists.mag-sol.com/mailman/listinfo/perlanet <http://lists.mag- sol.com/mailman/listinfo/perlanet> To report bugs in Perlanet, please use the CPAN request tracker. You can either use the web page at <http://rt.cpan.org/Public/Bug/Report.html?Queue=Perlanet> or send an email to bug-Perlanet@rt.cpan.org. SEE ALSO
o perlanet o Plagger AUTHOR
Dave Cross, <dave@mag-sol.com> COPYRIGHT AND LICENSE
Copyright (C) 2008 by Magnum Solutions Ltd. This progam library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-03-17 PERLANET(1p)
All times are GMT -4. The time now is 03:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy