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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:29:13+00:00 2026-05-11T17:29:13+00:00

What is the simplest way to remove all the carriage returns \r from a

  • 0

What is the simplest way to remove all the carriage returns \r from a file in Unix?

  • 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-11T17:29:14+00:00Added an answer on May 11, 2026 at 5:29 pm

    I’m going to assume you mean carriage returns (CR, "\r", 0x0d) at the ends of lines rather than just blindly within a file (you may have them in the middle of strings for all I know). Using this test file with a CR at the end of the first line only:

    $ cat infile
    hello
    goodbye
    
    $ cat infile | od -c
    0000000   h   e   l   l   o  \r  \n   g   o   o   d   b   y   e  \n
    0000017
    

    dos2unix is the way to go if it’s installed on your system:

    $ cat infile | dos2unix | od -c
    0000000   h   e   l   l   o  \n   g   o   o   d   b   y   e  \n
    0000016
    

    If for some reason dos2unix is not available to you, then sed will do it:

    $ cat infile | sed 's/\r$//' | od -c
    0000000   h   e   l   l   o  \n   g   o   o   d   b   y   e  \n
    0000016
    

    If for some reason sed is not available to you, then ed will do it, in a complicated way:

    $ echo ',s/\r\n/\n/
    > w !cat
    > Q' | ed infile 2>/dev/null | od -c
    0000000   h   e   l   l   o  \n   g   o   o   d   b   y   e  \n
    0000016
    

    If you don’t have any of those tools installed on your box, you’ve got bigger problems than trying to convert files 🙂

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

Sidebar

Related Questions

What is the simplest way to remove the header row from a flat file
What is the simplest way to remove a trailing slash from each parameter in
I'm looking for a simplest way to remove duplication in my WPF code. Code
What is the simplest way of taking the comment/s from the metadata of a
what is the simplest way to get all rows where a complex condition holds
What's the simplest way to list all the files in a git repo a
What's the simplest/canonical way to create an empty file in C#/.NET? The simplest way
What is the simplest way to call a program from with a piece of
What is the simplest way to forcefully delete a directory and all its subdirectories
The simplest way to launch a web browser from within a blackberry app is:

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.