I was trying to format a chat log for a friend that looks like this:
John Smith > hello Jane doe > hey how are you? John Smith > Pretty good thanks
and she wants to format it like this:
John Smith > hello
Jane doe > hey how are you?
John Smith > Pretty good thanks
Simply entering a new line after > is not good enough as it would not format correctly, so I need to insert a new line 3 white spaces, or 2 words prior to the “>” so the name is captured too.
So far I only have a new line after > :
/usr/bin/perl -p -i -e “s/>/>\n/g” *.txt
Edit: There are about 20+ different chat names involved so it would be great to do this without entering all their names since they may vary, and I’d like to learn from the exercise for fun.
Thanks for reading
Try this one:
Test I used for the regex:
It does add an extra newline to the beginning of the file, but if that doesn’t bother you then I think it should work.
Edit: It will also fail if someone used a
>character in one of their messages for some reason (if it was preceded by a space and two words, anyway).