perl - Grep command to find blank line - works in terminal, not in the file itself? -


i writing perl script, called qmail each incoming mail, parse content , find body of email. reason doing add user information database, append body, , forward address (a listserv).

unsolveable problem this:

cat dbody.txt|grep -a1000 '^\s*$' 

purpose: find first blank line (being end of header information) , return after that

when run line command line (using terminal) (ie. directly) - works fine. returns body of email.

when run in script - it doesn't.

have tested endlessly , cannot think of reason why be, or should change. help!

lines script - first "test" - works fine.

$test =`cat dbody.txt|grep -a1000 '^\s*$'`; $body= `cat dbody.txt|grep -a1000 '2,/^$/d'`; 

when print above final email - $test returns full text (as test), $body remains blank.

you can use perl this:

use strict; use warnings; $body; open $file, "<", "dbody.txt" or die("$!"); while (<$file>) {     $body .= $_ if defined $body;     $body  = "" if not defined $body , /^$/; } close $file; print $body; 

or, escape dollar signs:

$body= `grep -a1000 '2,/^\$/d' dbody.txt`; 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -