Sponsored Content
Top Forums Shell Programming and Scripting sed to extract a multiline subject from a mail message Post 302766851 by twisterbr on Tuesday 5th of February 2013 02:52:00 PM
Old 02-05-2013
Quote:
Originally Posted by alister
There's no \(...\) expression for the \1 backreference to refer to.

Appending a string to the pattern space does not require backreferences:
Instead of s/\(.*\)/\1 string/, use s/.*/& string/

If you want to append something to the line following the line that begins with "Subject:":
Code:
/^Subject:/{n; s/.*/& addendum/;}

Regards,
Alister

---------- Post updated at 02:37 PM ---------- Previous update was at 02:00 PM ----------


Test whether the pattern space contains \nDate: then insert the string appropriately (either before the newline if there's a match or at the end of the pattern space if there isn't).

Regards,
Alister
Hello Alister, thanks for your help!! but I was thinking in a more flexible way on doing that. I mean, what if the next line is not 'Date:'?

I want to do like this: "If the next line after '^Subject:' starts with a blank space, write the following string at the end of it.. if not, write at the end of the "^Subject:" line."
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete multiline string from file using sed.

Hi, I have file which has the following content... GOOD MORNING **********WARNING********** when it kicks from the kickstart, sshd daemon should start at last. (WHEN KICKING ITSELF, NOT AFTER KICKING). /etc/rc3.d/S55sshd ( run level specification for sshd is 55, now I would want to... (4 Replies)
Discussion started by: skmdu
4 Replies

2. Shell Programming and Scripting

Multiline pattern search using sed or awk

Hi friends, Could you please help me to resolve the below issue. Input file :- <Node> <username>abc</username> <password>ABC</password> <Node> <Node> <username>xyz</username> <password>XYZ</password> <Node> <Node> <username>mnp</username> ... (3 Replies)
Discussion started by: haiksuresh
3 Replies

3. Shell Programming and Scripting

sed multiline substitution if a condition holds

Hi. I have the following text file (more precisely a Matlab script): dummy1 = 5; varx = 'false'; dummy2 = 6; % ... some general commands % ... dummy3 = 7; vary = 'option1'; dummy4 = 8; Using sed I want to do the following action: IF varx = 'false' vary='NEW_VALUE_1'... (11 Replies)
Discussion started by: plsrn
11 Replies

4. UNIX for Dummies Questions & Answers

sed multiline pattern match

How can I write a script that takes a cisco config file and outputs every occurrence of two, or more, pattern matches through the whole config file? For example, out of a config file, i want to print out every line with interface, description and ip address through the whole file, and disregard... (3 Replies)
Discussion started by: knownasthatguy
3 Replies

5. UNIX for Dummies Questions & Answers

Need Multiline sed help!!

Hey everyone, I'm new to sed and I need to create a script for inserting one line of code at the beginning of every method in a Xcode project (over 6,000 methods). Each method Structure is (+ or -) (Various declarations-- could span multiple lines) ({) I've tried for days, any guidance would be... (2 Replies)
Discussion started by: jimmyz
2 Replies

6. Shell Programming and Scripting

Multiline sed

Hi guys, I am fairly comfortable with using the sed command if the string to be replaced is all on a single line. I was wondering is it possible to use sed command in a multiline way ? Say for example I have the below string on 2 different lines: { "key": "brandNameA", ... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

7. Shell Programming and Scripting

[sed]: Substitute a string with a multiline value

Dear all, I try to replace a string of characters in a file (MyFile.txt) by a multiline value of the variable "Myvar": $ cat MyFile.txt DESCRIPTION '@TargetTable SCHEMA' ( @InputFlowDef ); $ The content of Myvar: $ echo "$Myvar" col1 , col2 , col3 $ (4 Replies)
Discussion started by: dae
4 Replies

8. Shell Programming and Scripting

sed multiline problem

I'm trying to replicate the sed output on p.108 of Sed&Awk,by Doughery & Robbins, 2nd edition. I'm on a Windows 10 Surface Pro, running Cygwin for 64-bit versions of Windows. Input text saved in text file called data_p108.txt: Consult Section 3.1 in the Owner and Operator Guide for a... (9 Replies)
Discussion started by: prooney
9 Replies

9. 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
PCRE_DFA_EXEC(3)					     Library Functions Manual						  PCRE_DFA_EXEC(3)

NAME
PCRE - Perl-compatible regular expressions SYNOPSIS
#include <pcre.h> int pcre_dfa_exec(const pcre *code, const pcre_extra *extra, const char *subject, int length, int startoffset, int options, int *ovector, int ovecsize, int *workspace, int wscount); DESCRIPTION
This function matches a compiled regular expression against a given subject string, using an alternative matching algorithm that scans the subject string just once (not Perl-compatible). Note that the main, Perl-compatible, matching function is pcre_exec(). The arguments for this function are: code Points to the compiled pattern extra Points to an associated pcre_extra structure, or is NULL subject Points to the subject string length Length of the subject string, in bytes startoffset Offset in bytes in the subject at which to start matching options Option bits ovector Points to a vector of ints for result offsets ovecsize Number of elements in the vector workspace Points to a vector of ints used as working space wscount Number of elements in the vector The options are: PCRE_ANCHORED Match only at the first position PCRE_BSR_ANYCRLF R matches only CR, LF, or CRLF PCRE_BSR_UNICODE R matches all Unicode line endings PCRE_NEWLINE_ANY Recognize any Unicode newline sequence PCRE_NEWLINE_ANYCRLF Recognize CR, LF, and CRLF as newline sequences PCRE_NEWLINE_CR Set CR as the newline sequence PCRE_NEWLINE_CRLF Set CRLF as the newline sequence PCRE_NEWLINE_LF Set LF as the newline sequence PCRE_NOTBOL Subject is not the beginning of a line PCRE_NOTEOL Subject is not the end of a line PCRE_NOTEMPTY An empty string is not a valid match PCRE_NO_START_OPTIMIZE Do not do "start-match" optimizations PCRE_NO_UTF8_CHECK Do not check the subject for UTF-8 validity (only relevant if PCRE_UTF8 was set at compile time) PCRE_PARTIAL Return PCRE_ERROR_PARTIAL for a partial match PCRE_DFA_SHORTEST Return only the shortest match PCRE_DFA_RESTART This is a restart after a partial match There are restrictions on what may appear in a pattern when using this matching function. Details are given in the pcrematching documenta- tion. A pcre_extra structure contains the following fields: flags Bits indicating which fields are set study_data Opaque data from pcre_study() match_limit Limit on internal resource use match_limit_recursion Limit on internal recursion depth callout_data Opaque data passed back to callouts tables Points to character tables or is NULL The flag bits are PCRE_EXTRA_STUDY_DATA, PCRE_EXTRA_MATCH_LIMIT, PCRE_EXTRA_MATCH_LIMIT_RECURSION, PCRE_EXTRA_CALLOUT_DATA, and PCRE_EXTRA_TABLES. For this matching function, the match_limit and match_limit_recursion fields are not used, and must not be set. There is a complete description of the PCRE native API in the pcreapi page and a description of the POSIX API in the pcreposix page. PCRE_DFA_EXEC(3)
All times are GMT -4. The time now is 06:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy