Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 988031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:34:46+00:00 2026-05-16T05:34:46+00:00

I was trying to format a chat log for a friend that looks like

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:34:47+00:00Added an answer on May 16, 2026 at 5:34 am

    Try this one:

    perl -p -i -e "s/(\w+\s\w+\s*>)/\n\1/g" log.txt
    

    Test I used for the regex:

    [21:21:23] ~ $ echo 'John Smith > hello Jane doe > hey how are you? John Smith > Pretty good thanks Susie Someone > hi guys' > log.txt
    [21:21:24] ~ $ more log.txt 
    John Smith > hello Jane doe > hey how are you? John Smith > Pretty good thanks Susie Someone > hi guys
    [21:21:27] ~ $ perl -p -i -e "s/(\w+\s\w+\s>)/\n\1/g" log.txt
    [21:21:34] ~ $ more log.txt 
    
    John Smith > hello 
    Jane doe > hey how are you? 
    John Smith > Pretty good thanks 
    Susie Someone > hi guys
    [21:21:37] ~ $ 
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to format this and other elements alike, so it would look like
I'm trying to format my grid view so it looks like the following: so
I am trying to format some c# output so that a number always has
I'm trying to format a table from XML. Lets say I have this line
I'm trying to format strings in XSLT that needs to be in pascal case
I'm trying to format a box to look like a status update like feature.
I am trying to format a linked list so that it prints 5 nodes
I am trying to format a double in C# such that it uses the
I´m trying to format my class in FlashDevelop. This class has 1132 lines of
im trying to format this string into a fixed column style but cant get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.