Sponsored Content
Top Forums Shell Programming and Scripting Multi line regex for search and replace Post 302895423 by sol_nov on Monday 31st of March 2014 05:04:46 PM
Old 03-31-2014
Power [Solved] Multi line regex for search and replace

I have text file like below:

a.txt
Code:
Server=abc
Run=1
Time=120.123
Tables=10
Sessions=16
Time=380.123
Version=1.1
Jobs=5

Server=abc
Run=2
Time=160.123
Tables=15
Sessions=16
Time=400.258
Version=2.0
Jobs=5

Server=abc
Run=3
Time=180.123
Tables=20
Sessions=16
Time=450.889
Version=2.1
Jobs=5

I am trying to replace

Code:
Time=450.889
Version=2.1

with

Code:
EndTime=450.889
Version=2.1

I was trying like
Code:
perl -pi -e 's/^Time=\(.*\)\Version=\(.*\)/EndTime=\1\nVersion=\2/' a.txt

But it doesn't seem to work.

Can you guys help me out.

Thanks

Last edited by sol_nov; 03-31-2014 at 06:15 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and replace multi-line text in files

Hello I need to search for a mult-line text in a file exfile1 and replace that text with another text. The text to search for is in exfile2 and the replacement text is in exfile3. I work with kornshell under AIX and need to do this with a lot of files. (the file type is postscript and they need... (10 Replies)
Discussion started by: marz
10 Replies

2. Shell Programming and Scripting

perl regex multi line cut

hello mighty all there's a file with lots of comments.. some of them looks like: =comment blabla blablabla bla =cut i'm trying to cut this out completely with this code: $line=~s/^=.+?=cut//sg; but no luck also tryed to change it abit but still I don't understand how the... (9 Replies)
Discussion started by: tip78
9 Replies

3. Shell Programming and Scripting

sed - multi-line regex syntax eval puzzle

sed novice bashing away at this.... I am trying to build a sed script that will find the instances of "cn" that have more than one "DirXML" value on them.... see sample below: I am not having any luck with any variation that tries to find "DirXML.*\nDirXML.*". Isn't there a way to get sed to... (6 Replies)
Discussion started by: gosleddog
6 Replies

4. Shell Programming and Scripting

Multi-Line Search and Replace

There appears to be several threads that touch on what I'm trying to do, but nothing quite generic enough. What I need to do is search through many (poorly coded) HTML files and make changes. The catch is that my search string may be on one line or may be on several lines. For example there... (5 Replies)
Discussion started by: bisbell
5 Replies

5. Shell Programming and Scripting

Global search and replace multi line file

Hello I need to search for a mult-line strngs(with spaces in between and qoted) in a file1 and replace that text with Fixed string globally in file1. The strng to search for is in file2. The file is big with some 20K records. so speed and effciency is required file1: (where srch & rplc... (0 Replies)
Discussion started by: Hiano
0 Replies

6. Emergency UNIX and Linux Support

search replace regex question

Hi, I need to run a search and replace on a large database, what I need to change is all instances of #### (eg. 1764 or 1964) to (####) (eg. (1764) or (1964)) But there might be other numbers in there such as (1764) and I do not need those changed to ((1764)) How can I... (7 Replies)
Discussion started by: lawstudent
7 Replies

7. Shell Programming and Scripting

Regex:search/replace but not for escaped character

Hi Input: - -- --- ---- aa-bb-cc aa--bb--cc aa---bb---cc aa----bb----cc Output: . - -. -- aa.bb.cc (7 Replies)
Discussion started by: chitech
7 Replies

8. Shell Programming and Scripting

Regex - search and replace

I have file which contains data in the following format all in a single line: BDW_PUBLN_ID DECIMAL(18:0) NOT NULL PRIMARY INDEX ARGO_ACCT_DEP_PI ( OFC_ID ,CSHBX_ID ,TRXN_SEQ_NUM ,PROCG_DT ) PARTITION BY RANGE_N(PROCG_DT BETWEEN DATE '2012-03-01' AND DATE '2014-12-31' EACH INTERVAL '1' MONTH );... (4 Replies)
Discussion started by: ysvsr1
4 Replies

9. Shell Programming and Scripting

Get multi-line sed not to run if regex is found

Hello, everyone. Thanks for taking the time to read my post. I have nagios config files for which I'm adding the custom variable _mac_address. I have a sed script that places this variable into an existing file. The problem I'm having is if a line in the file is commented out, I don't want the... (2 Replies)
Discussion started by: JimBass
2 Replies

10. UNIX for Beginners Questions & Answers

Need help to use regex to do search and replace. Don't know how to and can't figure out how :(

Hi, Below is an excerpt from a 20000+ lines and I want to do a search and replace of a specific string but I don't know how and I can't figure out how to. Can't find an example from Google or anywhere to do what I am wanting to do. A 2018-11-21 08:42:17 TEST_TEST 2018-11-21... (9 Replies)
Discussion started by: newbie_01
9 Replies
Net::Whois::Parser(3pm) 				User Contributed Perl Documentation				   Net::Whois::Parser(3pm)

NAME
Net::Whois::Parser - module for parsing whois information SYNOPSIS
use Net::Whois::Parser; my $info = parse_whois( domain => $domain ); my $info = parse_whois( raw => $whois_raw_text, domain => $domain ); my $info = parse_whois( raw => $whois_raw_text, server => $whois_server ); $info = { nameservers => [ { domain => 'ns.example.com', ip => '123.123.123.123' }, { domain => 'ns.example.com' }, ], emails => [ 'admin@example.com' ], domain => 'example.com', somefield1 => 'value', somefield2 => [ 'value', 'value2' ], ... }; # Your own parsers sub my_parser { my ( $text ) = @_; return { nameservers => [ { domain => 'ns.example.com', ip => '123.123.123.123' }, { domain => 'ns.example.com' }, ], emails => [ 'admin@example.com' ], somefield => 'value', somefield2 => [ 'value', 'value2' ], }; } $Net::Whois::Parser::PARSERS{'whois.example.com'} = &my_parser; $Net::Whois::Parser::PARSERS{'DEFAULT'} = &my_default_parser; # If you want to get all values of fields from all whois answers $Net::Whois::Parser::GET_ALL_VALUES = 1; # example # Net::Whois::Raw returns 2 answers $raw = [ { text => 'key: value1' }, { text => 'key: value2'}]; $data = parse_whois(raw => $raw); # If flag is off parser returns # { key => 'value2' }; # If flag is on parser returns # { key => [ 'value1', 'value2' ] }; # If you want to convert some field name to another: $Net::Whois::Parser::FIELD_NAME_CONV{'Domain name'} = 'domain'; # If you want to format some fields. # I think it is very useful for dates. $Net::Whois::Parser::HOOKS{'expiration_date'} = [ &format_date ]; DESCRIPTION
Net::Whois::Parser module provides Whois data parsing. You can add your own parsers for any whois server. FUNCTIONS
parse_whois(%args) Returns hash of whois data. Arguments: 'domain' - domain 'raw' - raw whois text 'server' - whois server 'which_whois' - option for Net::Whois::Raw::whois. Default value is QRY_ALL CHANGES
See file "Changes" in the distribution AUTHOR
Ivan Sokolov, "<ivsokolov@cpan.org>" COPYRIGHT &; LICENSE Copyright 2009 Ivan Sokolov This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-01-20 Net::Whois::Parser(3pm)
All times are GMT -4. The time now is 11:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy