-1

I have the following sed code that works in RH6 and sed 4.2.1

>> echo "SUSE Linux Enterprise Server 11 ( x86_64 ) VERSION = 11 PATCHLEVEL = 2" | sed s/.*VERSION\ =\ //
11 PATCHLEVEL = 2
>> sed --version
GNU sed version 4.2.1

but it fails at SUSE 11 and sed 4.1.5

>> echo "SUSE Linux Enterprise Server 11 ( x86_64 ) VERSION = 11 PATCHLEVEL = 2" | sed s/.*VERSION\ =\ //
sed: No match.
>> sed --version
GNU sed version 4.1.5

I found the following code works differently in the two versions. sed 4.1.5 in SUSE cannot match anything.

echo ab | sed s/.*//

Is it a known issue of sed? and does it have a solution?

Joe C
  • 2,757
  • 2
  • 26
  • 46
  • 1
    You have an answer, but I'm curious about your symptom: Did you really get `sed: No match.`? That doesn't look like a Sed error message; was it perhaps `bash: no match: s/.*VERSION = //`? You'd get that if `shopt -s failglob` happens to be in effect, stemming from the _shell_'s failed attempt to match that pattern against files in the current dir. (due to being unquoted). – mklement0 Apr 21 '17 at 02:00

2 Answers2

3

Since you didn't quote the asterisk, your shell is trying to glob it. On one of your systems this globbing fails and the original string is returned. On your other system it matches something and your substitution regex is destroyed. Always quote arguments that the shell might consider "special".

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
-1

I found sed 4.1.5 needs single quotes to make things work. The following works.

echo ab | sed 's/.*//'

But the sed 4.2.1 does not need this.

Joe C
  • 2,757
  • 2
  • 26
  • 46
  • 2
    It's not sed that's globbing it. It's the shell. You might have glob turned off on the older system and turned on on the newer system. – alvits Apr 21 '17 at 01:44