-2

I want to search through a WhatsApp conversation (dumped as txt file) for any message containing the string "I will tell to your mom" as well as the message before it.

However, I need to be able to match variations of the search string such as: - tell to your mom !! - teLl to Your Mom !!!!!!

Those should also be considered the same if same wording appears in the line before.

jmary
  • 121
  • 1
  • 5
  • 5
    Please [edit] your question and clarify what format you have the transcript in. I assume you're not expecting for help on how to do this in WhatsApp itself, so have you exported the conversation to a text file? Can we see an example of it? And, this time, without oversharing. – terdon Jul 19 '16 at 16:26
  • @don_crissti Similar, but not quite the same. Here, OP wants case-insensitive search for a string longer than one char. – Alex Stragies Jul 19 '16 at 18:23
  • @don_crissti: I don't mind deletion. I figured, there is probably a dupe/similar_q somewhere. For the record, I see the similarity too, but both OPs did not, and chose to use very different keywords in the title, so It may help future googleability to keep both. – Alex Stragies Jul 19 '16 at 18:37

1 Answers1

2

grep was built for this.

to search case_-i_nsensitive, and return 1 line _B_efore, use similar to

grep -i -B1 tell\ to\ your\ mom your_msg_dump_with_each_msg_on_seperate_line.txt

  • Ok I reached full answer with this :

    grep -i -B1 'tell to your mom' dump.txt | awk -F "-" '/1/ {print $2}' | awk '!seen[$0]++'

    First awk removes date and time, the second removes duplicate lines. The result is quite satisfying.

    – jmary Jul 20 '16 at 03:18