sed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question of multiple "-e" commands in one command line.


From: Assaf Gordon
Subject: Re: A question of multiple "-e" commands in one command line.
Date: Fri, 15 Nov 2019 20:59:38 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

Hello,

On 2019-11-15 6:24 p.m., George R Goffe wrote:
I'm hoping that this question is sent to the "right" forum.

This is indeed the right forum (assuming you are using GNU sed).

I use sed to edit html files. I perform multiple actions on these files. When I string the 
"-e" commands together I get a different result from when I string 2 "-e" sets. 
I'm a little confused due to my lack of regex and sed experience.
[...]

sed --posix -E -i -e 's@  *@ @g' -e 's@\n@@' -e 's@\r@@' -e 's@>@>\r\n @g' -e 
'/^$/d' -e '/^ $/d' file1
[...]

diff file1 file2
[...]

From a cursory look, I can think of one exapmle case that will result in
a difference: you are adding a "\n" in one of the regexes, and
subsequent '/^ $/' regex won't catch it (as the pattern space now has
two lines):

$ printf ">\n" | sed -e 's@>@>\r\n @g' -e '/^ $/d' | od -c
0000000   >  \r  \n      \n
0000005

$ printf ">\n" | sed -e 's@>@>\r\n @g' | sed -e '/^ $/d' | od -c
0000000   >  \r  \n
0000003



If the above doesn't solve the issue,
and because you are mentioning manipulating both "\r" and "\n",
few more questions to help us troubleshoot the issue:

1. Which platform are you using (e.g windows, cygwin, GNU/Linux, etc.) ?

2. Which sed version are you using (sed --version) ?

3. Is reproducible ?

4. Does the same happen if you using redirection to save the output
instead of using "sed -i" ?

5. Can you show the output of "diff" using "od -c" to verify which
characters are different, e.g.:
    diff file1 file2 | od -c

regards,
 - assaf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]