Results 1 to 4 of 4

Thread: Challenges for escaping of newlines in sed text replacement command

  1. #1

    Question Challenges for escaping of newlines in sed text replacement command

    A variable "XY" contains data like the following for a small test script.
    Code:
       aa_free_task_context
     | aa_free_domain_entries
    Now I stumble on an error message like the following.
    Code:
     elfring@Sonne:~> LANG=C sed "s%# Alternation placeholder%${XY//$'\n'/$'\\\\\n'}%g" my_test_template1.txt
    sed: -e expression #1, char 57: unterminated `s' command
    Should my approach for pattern substitution in a shell variable work also with this tool from the package "sed 4.2.2-7.1"?

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,109
    Blog Entries
    2

    Default Re: Challenges for escaping of newlines in sed text replacement command

    First,
    You might consider posting rather technical Dev questions in the Development/scripting forum, although many programming questions are answered in this Forum, when you're asking about constructing programming code the following link is better...
    https://forums.opensuse.org/forumdis...ming-Scripting

    As for your current question,
    It's a bit hard to figure out the cause of your error without seeing what came before, as further evidenced by a quick Google search on your specific error
    https://www.google.com/search?q=unte...60s%27+command

    You'll return various hits which among things suggest that your command didn't receive proper input.

    TSU

  3. #3

    Question Re: Challenges for escaping of newlines in sed text replacement command

    Quote Originally Posted by tsu2 View Post
    You'll return various hits which among things suggest that your command didn't receive proper input.
    Do you suggest to adjust the number of backslashes so that new-line characters will be preserved for the text substitution by the current sed command?

  4. #4

    Question Re: Challenges for escaping of newlines in sed text replacement command

    Quote Originally Posted by tsu2 View Post
    …, as further evidenced by a quick Google search on your specific error …
    How do you think about to discuss a question like "How do I insert a newline into the RHS of a substitution?" a bit more?

    Are you interested to improve results like the following?
    Code:
      elfring@Sonne:~> sed "s%# Alternation placeholder%${XY//$'\n'/$'\\\\n'}%g" test_template1.txt              
    -------------------------                                                                                                                                                    
       aa_free_task_context\n | aa_free_domain_entries                                                                                                                           
    +++++++++++++++++++++++++                                                                                                                                                    
    elfring@Sonne:~> sed "s%# Alternation placeholder%${XY//$'\n'/$'\\\\\\n'}%g" test_template1.txt            
    ------------------------- 
       aa_free_task_context\ 
     | aa_free_domain_entries 
    +++++++++++++++++++++++++

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •