LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2011, 09:46 AM   #1
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Rep: Reputation: 24
sed terminated prematurely by presence of \c in input


Sed seems to react to the presence of "\" in its input if the immediately following character makes the pair a recognizable code. In the code following see that the "\a" and "\b" are missing in the output, and that the "\c" caused sed to terminate at that point. Is there any way to prevent it reacting like this?
Code:
g  y="the shell built-in command. The following character sequences 
> have special meaning: 
> \a Alert (bell). 
> \b Backspace. 
> 
> \c Suppress trailing newline. 
> \f Form feed. 
> \n Newline. 
> \r Carriage return. 
> 
> \t Horizontal tab. 
> \v Vertical tab. 
> 
> \\ 
> Literal backslash. 
> \nnn 
> The octal character whose ASCII code is nnn. 
> Options"
g  z="the"
g  x="Options"
g  w=$(echo -e "$y"|sed -n -e "/$z/,/$x/ p")
g  echo "$w"
the shell built-in command. The following character sequences 
have special meaning: 
 Alert (bell). 
 Backspace. 
g
Same commands ready for pasting.
Code:
y="the shell built-in command. The following character sequences 
have special meaning: 
\a Alert (bell). 
\b Backspace. 

\c Suppress trailing newline. 
\f Form feed. 
\n Newline. 
\r Carriage return. 

\t Horizontal tab. 
\v Vertical tab. 

\\ 
Literal backslash. 
\nnn 
The octal character whose ASCII code is nnn. 
Options"
z="the"
x="Options"
w=$(echo -e "$y"|sed -n -e "/$z/,/$x/ p")
echo "$w"
 
Old 06-17-2011, 09:57 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

I don't think sed is the culprit, but the echo command is.

Try this: w=$(echo "$y"|sed -n -e "/$z/,/$x/ p")

The -e is removed, this from the echo man page:
Quote:
-e enable interpretation of backslash escapes
The -e in the sed command is also not needed in this case, but it doesn't do any harm.

Hope this helps.
 
1 members found this post helpful.
Old 06-17-2011, 10:03 AM   #3
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by druuna View Post
Hi,

I don't think sed is the culprit, but the echo command is.

Try this: w=$(echo "$y"|sed -n -e "/$z/,/$x/ p")

The -e is removed, this from the echo man page:

The -e in the sed command is also not needed in this case, but it doesn't do any harm.

Hope this helps.
Ah, thank you. I always include -e with echo so it will interpret the "\n"s, never thought about its extended meaning.
 
Old 06-17-2011, 10:05 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk or sed to use CSV as input and XML as template and output to a single file bridrod Linux - Newbie 6 03-13-2012 07:00 PM
[SOLVED] How sed can catch variable from input drele Programming 5 02-03-2011 12:50 AM
Using sed to prepare my input file erickFis Linux - Software 4 11-04-2009 04:33 AM
prematurely terminated connection during a large file transfer rob_xx17 Linux - Networking 7 03-22-2006 10:15 AM
sed input from `ls` rashy49 Programming 4 03-06-2005 02:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration