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

  • Home
  • SEARCH
  • 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 316555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:23:42+00:00 2026-05-12T08:23:42+00:00

What is the simplest way to parse line continuation characters? This seems like such

  • 0

What is the simplest way to parse line continuation characters? This seems like such a basic action that I’m surprised there’s no basic command for doing this. ‘while read’ and ‘while read -r’ loops don’t do what I want, and the easiest solution I’ve found is the sed solution below. Is there a way to do this with something basic like tr?

$ cat input
Output should be \
one line with a '\' character.
$ while read l; do echo $l; done < input
Output should be one line with a '' character.
$ while read -r l; do echo $l; done < input
Output should be \
one line with a '\' character.
$ sed '/\\$/{N; s/\\\n//;}' input
Output should be one line with a '\' character.
$ perl -0777 -pe 's/\\\n//s' input
Output should be one line with a '\' character.

  • 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-12T08:23:42+00:00Added an answer on May 12, 2026 at 8:23 am

    If by “simplest” you mean concise and legible, I’d suggest your perl-ism with one small modification:

    $ perl -pe 's/\\\n//' /tmp/line-cont
    

    No need for the possibly memory intensive ... -0777 ... (whole file slurp mode) switch.

    If, however, by “simplest” you mean not the leaving shell, this will suffice:

    $ { while read -r LINE; do
        printf "%s" "${LINE%\\}";    # strip line-continuation, if any
        test "${LINE##*\\}" && echo; # emit newline for non-continued lines
        done; } < /tmp/input
    

    (I prefer printf "%s" $USER_INPUT to echo $USER_INPUT because echo cannot portably be told to stop looking for switches, and printf is commonly a built-in anyway.)

    Just tuck that in a user-defined function and never be revolted by it again. Caution: this latter approach will add a trailing newline to a file which lacks one.

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

Sidebar

Related Questions

Given a string like: 0.123, 0.456 what is the simplest way to parse the
Possible Duplicate: What's the simplest way to parse URL parameters in Clojure? I'd like
What's the simplest way to parse an Excel file in Perl? Converting it to
I have Python code to call a REST service that is something like this:
what is the simplest way to upload multi images (like 30-50) at once using
What is the simplest way to reverse the case of all alphabetic characters in
What is the simplest way to display this kind of feed? I've heard you
What's the simplest way to print all matches (either one line per match or
I think the simplest way would be (!$var and $var!=0) , but is there
What is the easiest and simplest way to save a string so that you

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.