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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:23:40+00:00 2026-06-14T15:23:40+00:00

Sorry for this question, I know that this is a recurrent topic, but I’m

  • 0

Sorry for this question, I know that this is a recurrent topic, but I’m incapable of solving my problem, which in fact, is simple to describe: I want to write into a file the output of an execution as it is. I mean, I have an output like this (sorry for the mess):

.251.242.133|:80... connected.\r\nHTTP request sent, awaiting response... 200 OK\r\nLength: 2371567 (2.3M) [application/x-gzip]\r\nSaving to: `110907_ERP000591.tar.gz\'\r\n\r\n\r 0% [                                       ] 0           --.-K/s              \r 0% [                                       ] 23,003       104K/s              \r 3% [>                                      ] 82,863       184K/s              \r 8% [==>                                    ] 192,363      282K/s              \r15% [=====>                                 ] 371,943      411K/s              \r26% [=========>                             ] 634,175      563K/s              \r39% [==============>                        ] 925,283      680K/s              \r52% [===================>                   ] 1,250,295    790K/s              \r63% [=======================>               ] 1,497,035    830K/s              \r73% [===========================>           ] 1,732,663    861K/s              \r81% [==============================>        ] 1,937,063    867K/s              \r88% [=================================>     ] 2,099,123    855K/s              \r95% [====================================>  ] 2,268,483    847K/s              \r100%[======================================>] 2,371,567    849K/s   in 2.7s    \r\n\r\n2012-11-01 15:34:10 (849 KB/s) - `110907_ERP000591.tar.gz\' saved [2371567/2371567]\r\n\r\n110907_ERP000591/\r\n110907_ERP000591/1_110907_ERP000591_2_fastq.txt\r\n110907_ERP000591/1_110907_ERP000591_1_fastq.txt\r\n/home/travis/opt/bcbb/nextgen/tests/data/automated/../100326_FC6107FAAXX\r\n--2012-11-01 15:34:10--  http://chapmanb.s3.amazonaws.com/100326_FC6107FAAXX.tar.gz\r\nResolving chapmanb.s3.amazonaws.com (chapmanb.s3.amazonaws.com)... 205.251.242.133\r\nConnecting to chapmanb.s3.amazonaws.com (chapmanb.s3.amazonaws.com)|205.251.242.133|:80... connected.\r\nHTTP request sent, awaiting response... 200 OK\r\nLength: 7014592 (6.7M) [application/x-gzip]\r\nSaving to: `100326_FC6107FAAXX.tar.gz\'\r\n\r\n\r 0% [                                       ] 0           --.-K/s              \r 0% [                                       ] 17,163      77.9K/s              \r 0% [                                       ] 64,775       147K/s              \r 2% [                                       ] 174,843      263K/s              \r 5% [=>                                     ] 399,683      456K/s              \r12% [===>                                   ] 866,883      790K/s              \r25% [========>                              ] 1,798,363   1.33M/s              \r45% [================>                      ] 3,178,955   1.90M/s              \r65% [========================>              ] 4,592,803   2.41M/s              \r65% [========================>              ] 4,629,303   2.17M/s              \r67% [=========================>             ] 4,761,595   2.02M/s              \r74% [============================>          ] 5,245,423   2.03M/s              \r83% [===============================>       ] 5,862,435   2.08M/s              \r100%[======================================>] 7,014,592   2.46M/s   in 2.7s    \r\n\r\n2012-11-01 15:34:13 (2.46 MB/s) - 

So, as you can see, I have a weirdly formatted output, which is shown like this in the terminal:


/home/travis/opt/bcbb/nextgen/tests/data/automated/../100326_FC6107FAAXX
--2012-11-01 15:34:10--  http://chapmanb.s3.amazonaws.com/100326_FC6107FAAXX.tar.gz
Resolving chapmanb.s3.amazonaws.com (chapmanb.s3.amazonaws.com)... 205.251.242.133
Connecting to chapmanb.s3.amazonaws.com (chapmanb.s3.amazonaws.com)|205.251.242.133|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7014592 (6.7M) [application/x-gzip]
Saving to: `100326_FC6107FAAXX.tar.gz'

100%[======================================>] 7,014,592   2.46M/s   in 2.7s    

2012-11-01 15:34:13 (2.46 MB/s) - `100326_FC6107FAAXX.tar.gz' saved [7014592/7014592]

Much nicer… I want to write the output to a file with this form, so I cant just strip the \r\n or something like that, because this way will appear one line for each step in the progress of the download. I just want to write a file with the final output.

Any help?

EDIT:

Sorry, I should have been clearer: It’s not the result of a command but, as commented below, the result of the parsing of a json file. You can reproduce the output:


import urllib
import json

string_to_write = json.loads(urllib.urlopen('https://travis-ci.org/jobs/3019024.json').read())['log']
  • 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-06-14T15:23:41+00:00Added an answer on June 14, 2026 at 3:23 pm

    This ought to work:

    re.sub(r"(?m)^.*\r(?!$)", "", text)
    

    The (?m) flag indicates that this is a multiline regex, so that ^ and $ match the beginning and end of each line, rather than the whole text.

    So, we match everything .* from the start of the line ^ up to and including a carriage return \r, unless that carriage return is immediately followed by the end of the line (?!$) – as it will be if your text contains CRLF linebreaks. And, replace the match with the empty string.

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

Sidebar

Related Questions

sorry for this question, but i dont know where to search for it, or
Sorry, I know this question is easy, but I don't know how to get
Well I know that this question may be asked many times but certainly I've
Hey, sorry for posting this here, I know that this question better suites into
Sorry for this question, I dont know if i've understood the concept, but SQLite
Sorry if this question may be simple, but I can't seem to find an
Sorry if this question sounds stupid, but I only know HTML/CSS and so I'm
Good afternoon, I'm sorry if this question is too silly, but I don't know
I know that there's a very similar topic for this question, however I'm trying
Sorry in advance everyone for this question as I know the cascading select boxes

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.