Hello, I thought I would the rest alone, but I cannot make it.
I had to remove "/^From /" before main part of AWK, so it doesnt omit text behind block, which starts with "From ", separated with blank line. But this doesn't work either?
I'm using extra VARIABLE WRITE_OTHER so awk doesn't print unnecessary text between MAIN_HEADER("From ") and SUB_HEADERS. But I want to have written text between SUB_HEADERS and next MAIL(sentence starting with "From ").
This is PETO.AWK, but it doesn't do what I would like to.
BEGIN {
# make 'records' to be separated by blank/empty lines
RS=FS=""
# create a pattern where something starts either one of listed strings
main_header="(^From )"
sub_headers="(^Message-ID
|(^Date
|(^From
|(^To
|(^Subject
"
#VARIABLE to help us avoid writing info about sending between header and
#message. 0 - false, 1 - true
}
# If a record starts with 'From ' ...
{
WRITE_OTHER=0
for(i=1; i<=NF; i++) {
if ( (msg % 1 == 0 && msg != 1 ) ) {
printf "Please press ENTER: "
cmd="read a"; cmd | getline foo
close(cmd)
}
# print the record number
printf("\n\n=== THIS is MAIL MESSAGE #%d ===\n\n", msg)
# iterate through the fields of a given 'record' - every field is a LINE,
# because records are 'blank line' separated sequences of lines
# if a record field (a line) matches a pattern 'headers' - print that field
if ( $i ~ main_header ) {
WRITE_OTHER = 0
print $i
msg++
}
else if ( $i ~ sub_headers ) {
WRITE_OTHER = 1
print $i
}
else if ( WRITE_OTHER == 1) {
print $i
}
}
}