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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:46:24+00:00 2026-06-08T17:46:24+00:00

I have some 100,000+ files with partially mangled data, mixed text+binary files (a single

  • 0

I have some 100,000+ files with partially mangled data, mixed text+binary files (a single file of jpg image data with http headers), where some header fields have dos style ^M^J line termination, and some only unix style ^J. When vim opens a file like this, it treats it as unix format. So all header lines where there is no ^M, one needs to be added. But this has proven to be very tough.

:1,11s/Cache-Control:.*\zs^M\{0,}$/^M/

doesn’t work, and i’ve tried all kinds of variations of that, even using \=printf(“%s”,”^M”) as substitution string. But the result is always a new empty line in the file.

The ONLY way i’m able to add a ^M by a command at all is by

:exe "normal A\<c-q>\<c-m>\<Esc>"

Ok so one way would be to first remove any existing ^M, and then add it by previous. But is there a more elegant, one command solution?

(So that there would be no more misunderstandings, here’s a short example of such a file:

HTTP/1.1 200 OK
Server: Apache/2.2.3
(more lines...)
Cache-Control: public, max-age=214748
(more lines...)

ÿØÿá Exif  II*            ÿì

)

Edit/solution: regarding 100,000+ files, here’s a version (regarding missing ^M only on cache-control lines) that only matches if ^M is missing (as not all files are mangled, this will save large amounts of time together with “update!”):

:1,11s/^Cache-Control:.\{-}\zs\(^M*$\)\(^M\)\@<!/\^M/i

  • 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-08T17:46:25+00:00Added an answer on June 8, 2026 at 5:46 pm

    A single command might look like :v/^M/s/$/\^M/. This uses <C-v><C-m>, which is to say… it inserts a literal ^M character that’s escaped with a backslash.

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

Sidebar

Related Questions

I have a text file with about 100,000 lines (5 MB), which is updated
I have some 100 files in which I need to replace: Eval(something) with Eval(something).ToEncodedString()
I have some 100 files to be merged from one branch to the other.
I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
I have a bunch of files (almost 100) which contain data of the format:
I'm creating a PHP script that imports some data from text files into a
I have a class extracting strings from a large file (100,000) lines and wanted
I have about a 100 csv files each 100,000 x 40 rows columns. I'd
In PHP, say that you have some code like this: $infrastructure = mt_rand(0,100); if
I have imageView with some frame imageView.frame = CGRectMake(0,0, 100, 100); imageView.contentMode = UIViewContentModeScaleAspectFit;

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.