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 7655301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:28:49+00:00 2026-05-31T12:28:49+00:00

I’ve been trying to convert this format: 2012-03-16 13:47:30.465 -0400 START Running Lab.script 19

  • 0

I’ve been trying to convert this format:

2012-03-16 13:47:30.465 -0400   START  Running    Lab.script    19    on_the

The only way I could figure it out was using sed, however when I try to use subprocess in python, it won’t read the proper command and it will give me an error. Also, it’s not the right format, I’d like it to be similar to csv.

This is what I’m working with currently:

   f = open("newlogfile.csv", "w")
   p = subprocess.Popen(["sed","-e","'s/^[ ]*//g'","-e","'s/\([0-9a-zA-Z\.]*\)","*/\1;/g'","LogFile.txt"], stdout=f, stderr=f)

   f.close()

I’m pretty new to using subprocess and very new to using sed, any help would be appreciated.

Thank you in advance

UPDATE:

  fin = csv.reader(open('LogFile.txt', 'rb'),delimiter='\t')
  fout = csv.writer(open('newLogFile.csv', 'w'))

  for row in fin:
    fout.writerow(';'.join(row))
  • 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-31T12:28:51+00:00Added an answer on May 31, 2026 at 12:28 pm

    You should really look into the csv module for a cleaner method of making this conversion, I believe you will want code that looks something like this:

    fin = csv.reader(open('LogFile.txt', 'rb'), delimiter='\t')
    fout = open('newLogFile.csv', 'w')
    for row in fin:
        fout.write(';'.join(row) + '\n')
    

    The rest of this answer should help to explain why your sed method isn’t working and how to fix it.

    Try changing your command list to the following:

    ["sed", "-e", "s/^[ ]*//g", "-e", "s/\([0-9a-zA-Z\.]*\)*/\1;/g", "LogFile.txt"]
    

    Note that the second s/.../.../g was split into two entries in your original example, which is likely what was causing the problem. Also you do not need the single quotes because Popen will do whatever escaping is necessary to pass the entire entry in the argument list to sed as a single argument.

    You should also replace stderr=f with stderr=subprocess.STDOUT, which is the correct way to send stderr to the same place as stdout.

    Complete code:

    f = open("newlogfile.csv", "w")
    args = ["sed", "-e", "s/^[ ]*//g", "-e", "s/\([0-9a-zA-Z\.]*\)*/\1;/g", "LogFile.txt"]
    p = subprocess.Popen(args, stdout=f, stderr=subprocess.STDOUT)
    f.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.