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
RELOAD(1)						User Contributed Perl Documentation						 RELOAD(1)

NAME
Apache::Reload - Reload Perl Modules when Changed on Disk Synopsis # Monitor and reload all modules in %INC: # httpd.conf: PerlModule Apache::Reload PerlInitHandler Apache::Reload # Reload groups of modules: # httpd.conf: PerlModule Apache::Reload PerlInitHandler Apache::Reload PerlSetVar ReloadAll Off PerlSetVar ReloadModules "ModPerl::* Apache::*" #PerlSetVar ReloadDebug On # Reload a single module from within itself: package My::Apache::Module; use Apache::Reload; sub handler { ... } 1; Description "Apache::Reload" reloads modules that change on the disk. When Perl pulls a file via "require", it stores the filename in the global hash %INC. The next time Perl tries to "require" the same file, it sees the file in %INC and does not reload from disk. This module's handler can be configured to iterate over the modules in %INC and reload those that have changed on disk or only specific modules that have registered themselves with "Apache::Reload". It can also do the check for modified modules, when a special touch-file has been modified. Note that "Apache::Reload" operates on the current context of @INC. Which means, when called as a "Perl*Handler" it will not see @INC paths added or removed by "Apache::Registry" scripts, as the value of @INC is saved on server startup and restored to that value after each request. In other words, if you want "Apache::Reload" to work with modules that live in custom @INC paths, you should modify @INC when the server is started. Besides, 'use lib' in the startup script, you can also set the "PERL5LIB" variable in the httpd's environment to include any non-standard 'lib' directories that you choose. For example, to accomplish that you can include a line: PERL5LIB=/home/httpd/perl/extra; export PERL5LIB in the script that starts Apache. Alternatively, you can set this environment variable in httpd.conf: PerlSetEnv PERL5LIB /home/httpd/perl/extra Monitor All Modules in %INC To monitor and reload all modules in %INC, simply add the following configuration to your httpd.conf: PerlModule Apache::Reload PerlInitHandler Apache::Reload Register Modules Implicitly To only reload modules that have registered with "Apache::Reload", add the following to the httpd.conf: PerlModule Apache::Reload PerlInitHandler Apache::Reload PerlSetVar ReloadAll Off # ReloadAll defaults to On Then any modules with the line: use Apache::Reload; Will be reloaded when they change. Register Modules Explicitly You can also register modules explicitly in your httpd.conf file that you want to be reloaded on change: PerlModule Apache::Reload PerlInitHandler Apache::Reload PerlSetVar ReloadAll Off PerlSetVar ReloadModules "My::Foo My::Bar Foo::Bar::Test" Note that these are split on whitespace, but the module list must be in quotes, otherwise Apache tries to parse the parameter list. The "*" wild character can be used to register groups of files under the same namespace. For example the setting: PerlSetVar ReloadModules "ModPerl::* Apache::*" will monitor all modules under the namespaces "ModPerl::" and "Apache::". Special "Touch" File You can also declare a file, which when gets touch(1)ed, causes the reloads to be performed. For example if you set: PerlSetVar ReloadTouchFile /tmp/reload_modules and don't touch(1) the file /tmp/reload_modules, the reloads won't happen until you go to the command line and type: % touch /tmp/reload_modules When you do that, the modules that have been changed, will be magically reloaded on the next request. This option works with any mode described before. Performance Issues This modules is perfectly suited for a development environment. Though it's possible that you would like to use it in a production environ- ment, since with "Apache::Reload" you don't have to restart the server in order to reload changed modules during software updates. Though this convenience comes at a price: o If the "touch" file feature is used, "Apache::Reload" has to stat(2) the touch file on each request, which adds a slight but most likely insignificant overhead to response times. Otherwise "Apache::Reload" will stat(2) each registered module or even worse--all mod- ules in %INC, which will significantly slow everything down. o Once the child process reloads the modules, the memory used by these modules is not shared with the parent process anymore. Therefore the memory consumption may grow significantly. Therefore doing a full server stop and restart is probably a better solution. Debug If you aren't sure whether the modules that are supposed to be reloaded, are actually getting reloaded, turn the debug mode on: PerlSetVar ReloadDebug On Threaded MPM and Multiple Perl Interpreters If you use "Apache::Reload" with a threaded MPM and multiple Perl interpreters, the modules will be reloaded by each interpreter as they are used, not every interpreters at once. Similar to mod_perl 1.x where each child has its own Perl interpreter, the modules are reloaded as each child is hit with a request. If a module is loaded at startup, the syntax tree of each subroutine is shared between interpreters (big win), but each subroutine has its own padlist (where lexical my variables are stored). Once "Apache::Reload" reloads a module, this sharing goes away and each Perl inter- preter will have its own copy of the syntax tree for the reloaded subroutines. Pseudo-hashes The short summary of this is: Don't use pseudo-hashes. They are deprecated since Perl 5.8 and will be removed in 5.10 Use an array with constant indexes. Its faster in the general case, its more guaranteed, and generally, it works. The long summary is that some work has been done to get this module working with modules that use pseudo-hashes, but it's still broken in the case of a single module that contains multiple packages that all use pseudo-hashes. So don't do that. Authors Matt Sergeant, matt@sergeant.org Stas Bekman (porting to mod_perl 2.0) A few concepts borrowed from "Stonehenge::Reload" by Randal Schwartz and "Apache::StatINC" (mod_perl 1.x) by Doug MacEachern and Ask Bjoern Hansen. See Also "Stonehenge::Reload" perl v5.8.0 2002-06-15 RELOAD(1)
All times are GMT -4. The time now is 05:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy