Sponsored Content
Top Forums Shell Programming and Scripting Need grep regex to extract multiline text between two strings Post 303043382 by mohtashims on Monday 27th of January 2020 06:51:19 AM
Old 01-27-2020
Need grep regex to extract multiline text between two strings

I have a file conatining the below:

Code:
---
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: 1746f03d57491b27158b0d3a48fca8b5fa85c0c2
  /tmp/conf/httpd.conf:
    hash: 1746f03d57491b27158b0d3a48fca8b5fa85c0c2
10.9.16.16:
  /tmp/tom5835113081224811756.jar:
    hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb
  /tmp/tom4603745991442278706.jar:
    hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb

I have a start pattern in variable myip="10.9.14.126"

The end pattern should ONLY be the colon [:] for the next IP / Host i.e the bold part here 10.9.16.16: or the end patter should be "EOF" (end of file) incase there is no Semicolon as the entry was the last antry the last IP in the file.

Thus my desired output for regex is below:

Code:
  /tmp/conf/extra/httpd-ssl.conf:
    hash: 1746f03d57491b27158b0d3a48fca8b5fa85c0c2
  /tmp/conf/httpd.conf:
    hash: 1746f03d57491b27158b0d3a48fca8b5fa85c0c2

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using AWK how to extract text between two same strings

I have a file like: myfile.txt it is easy to learn awk and begin awk scripting and awk has got many features awk is a powerful text processing tool Now i want to get the text between first awk and immediate awk not the third awk . How to get it ? its urgent pls help me and file is unevenly... (2 Replies)
Discussion started by: santosh1234
2 Replies

2. Shell Programming and Scripting

using awk to extract text between two constant strings

Hi, I have a file from which i need to extract data between two constant strings. The data looks like this : Line 1 SUN> read db @cmpd unit 60 Line 2 Parameter: CMPD -> "C00071" Line 3 Line 4 SUN> generate Line 5 tabint>ERROR: (Variable data) The data i need to extract is... (11 Replies)
Discussion started by: mjoshi
11 Replies

3. Shell Programming and Scripting

grep command to replace multiline text from httpd.conf file on Fedora

Hi, I am a newbie to shell scripting and to Linux environment as well. In my project I am trying to search for following text from the httpd.conf file <Directory '/somedir/someinnerdir'> AllowOverride All </Directory> and then remove this text and again rewrite the same text. The... (1 Reply)
Discussion started by: bhushan
1 Replies

4. UNIX for Dummies Questions & Answers

extract text between two strings exclusive

Hi, I'm trying to retrieve text between two strings excluding the two strings. So for example I have the following input: type=friend username=phone1 secret=password host=dynamic dtmfmode=rfc2833 mailbox=9664 context=sip insecure=very canreinvite=no nat=yes realm=192.168.1.122... (3 Replies)
Discussion started by: the1armedcoder
3 Replies

5. Shell Programming and Scripting

AWK: How to extract text lines between two strings

Hi. I have a text test1.txt file like:Receipt Line1 Line2 Line3 End Receipt Line4 Line5 Line6 Canceled Receipt Line7 Line8 Line9 End (9 Replies)
Discussion started by: TQ3
9 Replies

6. UNIX for Advanced & Expert Users

bash/grep/awk/sed: How to extract every appearance of text between two specific strings

I have a text wich looks like this: clid=2 cid=6 client_database_id=35 client_nickname=Peter client_type=0|clid=3 cid=22 client_database_id=57 client_nickname=Paul client_type=0|clid=5 cid=22 client_database_id=7 client_nickname=Mary client_type=0|clid=6 cid=22 client_database_id=6... (3 Replies)
Discussion started by: Pioneer1976
3 Replies

7. Shell Programming and Scripting

How to Extract text between two strings?

Hi, I want to extract some text between two strings in a line i am using following command i.e; awk '/-string1/,/-string2/' filename contents of file is--- line1 line2 aaa -bbb -ccc -string1 c,d,e -string2 line4 but it is showing complete line which is having searched strings. aaa... (19 Replies)
Discussion started by: emresearch
19 Replies

8. Shell Programming and Scripting

Extract text between two strings

Hi I have something like this: EXAMPLE 1 CREATE UNIQUE INDEX "STRING_1"."STRING_2" ON "BOSNI_CAB_EVENTO" ("CD_EVENTO" , "CD_EJECUCION" ) PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 5242880 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "DB1000_INDICES_512K"... (4 Replies)
Discussion started by: chrispaz81
4 Replies

9. Shell Programming and Scripting

Extract text between two strings

Hi, I have a text like these: ECHO "BEGGINING THE SHELL....." MV FILE1 > FILE2 UNIQ_ID=${1} PARTITION_1=`${PL}/Q${CON}.KSH "SELECT ....." PARTITION_2=`${PL}/Q${CON}.KSH "SELECT ........" ${PL}/Q${CON}.KSH "CREATE ...." IF .... ....... I would like to extract only text that only... (4 Replies)
Discussion started by: mierdatuti
4 Replies

10. Shell Programming and Scripting

Search for a text between two strings in a file using regex

Here is my sample file data: 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... (5 Replies)
Discussion started by: mohtashims
5 Replies
MasonX::Request::WithApacheSession(3pm) 		User Contributed Perl Documentation		   MasonX::Request::WithApacheSession(3pm)

NAME
MasonX::Request::WithApacheSession - Add a session to the Mason Request object SYNOPSIS
In your httpd.conf file: PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession PerlSetVar MasonSessionCookieDomain .example.com PerlSetVar MasonSessionClass Apache::Session::File PerlSetVar MasonSessionDirectory /tmp/sessions/data PerlSetVar MasonSessionLockDirectory /tmp/sessions/locks Or when creating an ApacheHandler object: my $ah = HTML::Mason::ApacheHandler->new ( request_class => 'MasonX::Request::WithApacheSession', session_cookie_domain => '.example.com', session_class => 'Apache::Session::File', session_directory => '/tmp/sessions/data', session_lock_directory => '/tmp/sessions/locks', ); In a component: $m->session->{foo} = 1; if ( $m->session->{bar}{baz} > 1 ) { ... } DESCRIPTION
This module integrates "Apache::Session" into Mason by adding methods to the Mason Request object available in all Mason components. Any subrequests created by a request share the same session. USAGE
To use this module you need to tell Mason to use this class for requests. This can be done in one of two ways. If you are configuring Mason via your httpd.conf file, simply add this: PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession If you are using a handler.pl file, simply add this parameter to the parameters given to the ApacheHandler constructor: request_class => 'MasonX::Request::WithApacheSession' METHODS
This class adds two methods to the Request object. o session This method returns a hash tied to the "Apache::Session" class. o delete_session This method deletes the existing session from persistent storage. If you are using the built-in cookie mechanism, it also deletes the cookie in the browser. CONFIGURATION
This module accepts quite a number of parameters, most of which are simply passed through to "Apache::Session::Wrapper". For this reason, you are advised to familiarize yourself with the "Apache::Session::Wrapper" documentation before attempting to configure this module. If you are creating your own Interp/ApacheHandler/CGIHandler object in a script or module, you should pass this object the parameters intended for "Apache::Session::Wrapper", prefixed with "session_". So to set the "class" parameter for "Apache::Session::Wrapper", you pass in a "session_class" parameter. If you are configuring Mason via your httpd.conf file, you should pass the "StudlyCaps" version of the name, prefixed by "MasonSession". So the "class" parameter would be "MasonSessionClass". A few examples: o class becomes session_class / MasonSessionClass o always_write becomes session_always_write / MasonSessionAlwaysWrite When running under ApacheHandler or CGIHandler, this module takes care of passing the "header_object" and "param_object" parameters to "Apache::Session::Wrapper". These will be the "Apache::Request" or "CGI.pm" objects, as applicable. The "cookie_name" parameter defaults to "MasonX-Request-WithApacheSession-cookie" when you use this module, instead of "Apache-Session- Wrapper-cookie". Finally, for backwards compatiblity, this module accepts a "session_args_param" parameter, which corresponds to the "param_name" parameter for "Apache::Session::Wrapper". SUPPORT
As can be seen by the number of parameters above, "Apache::Session" has way too many possibilities for me to test all of them. This means there are almost certainly bugs. Bug reports and requests for help should be sent to the mason-users list. See http://www.masonhq.com/resources/mailing_lists.html for more details. AUTHOR
Dave Rolsky, <autarch@urth.org> SEE ALSO
HTML::Mason perl v5.14.2 2012-12-01 MasonX::Request::WithApacheSession(3pm)
All times are GMT -4. The time now is 03:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy