Web Analytics Made Easy -
StatCounter Find line containing A and then find line containing B and replace ending " by ABC" - CodingForum

Announcement

Collapse
No announcement yet.

Find line containing A and then find line containing B and replace ending " by ABC"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Find line containing A and then find line containing B and replace ending " by ABC"

    Hello,

    i am trying to create a bash script that will update file (Thunderbird filtering file) adding new value to the filtering. I will publish the script for anyone to use it so everyone can create global filters for all accounts, but i need help/suggestion regarding following:

    Based on following quoted filter file content i think that to adjust one of the sections/filters (for example name="Body contains, delete (ABC)" one, i need to find the line containing "Body contains, delete (ABC)"
    and then from this line find first occurrence of "condition=" and on such line replace last character of that line " by a new phrase, for example OR (body,contains,$userinputphrase)"
    where $userinputphrase will be supplied by user using for example command: read -r -p "Enter phrase" userinputphrase
    and such phrase can be even complicated like: test "phrase2" $';\/ xyz
    (while i will need to convert " to \\" but that is another issue i will solve easily i think.)

    The filtering file msgFilterRules.dat looks like this for example:

    Code:
    name="Subject contains, delete"
    enabled="yes"
    type="17"
    action="Delete"
    condition="OR (subject,contains,spam message) OR (subject,contains,spam2 message)"
    
    name="Sender match, delete"
    enabled="yes"
    type="1"
    action="Delete"
    condition="OR (from,is,[email protected]) OR (from,contains,[email protected])"
    
    name="Body contains, delete (ABC)"
    enabled="yes"
    type="1"
    action="Delete"
    condition="OR (body,contains,Central Bank of Nigeria) OR (body,contains,test \\"phrase\\" $';\/ abc)"
    
    name="Subject & sender contains, delete"
    enabled="yes"
    type="1"
    action="Delete"
    condition="AND (subject,contains,badsubject) AND (from,contains,@baddomain.tld)"
    Can you please help with the right sed/awk command?
    Last edited by postcd; Feb 20, 2022, 09:25 AM.
Working...
X