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
Post a Comment