Unterminated Address Regex While Using Sed

unterminated address regex while using sed

You need to escape the [, or else it thinks its start of a group, and escape to / in your data.

sed -n '/^\[2015\/01\/01 03:46/,/^\[2015\/01\/01 03:47/p' Input.txt

or (thanks to nu11p01n73R)

sed -n '\|^\[2015/01/01 03:46|,\|^\[2015/01/01 03:47|p' Input.txt

sed unterminated address regex

Here's a version that doesn't use sed at all.

#!/usr/bin/perl

use strict;
use warnings;

my $filename = 'temp_stage.txt';

my $waha;

open my $fh, $filename or die("$0: $filename: $!");
while(<$fh>) {
# concatenate the lines from "orange" to blank (inclusive)
$waha .= $_ if(/orange/ .. /^$/);
}
close($fh);

print "$waha";

See perlop - Range-Operators for the .. operator used to capture the range.

unterminated address regex using variable in sed

So the problem here turned out to be newline characters that were being pulled in as part of the grep.
This is why populating $item manually worked - no '\n'

Thanks to Ed Morton for pointing me in the right direction. While

echo "$item" | cat -v

did not show anything I added '-t' to the readarray command to trim newline characters:

$readarray -t LINES < <(grep "#file = /mnt/var/" /etc/conf/service.conf)

After that things worked as expected.

sed error: unterminated address regex - bash script

Note to self: don't try to simplify the problem when asking it on SO.

I was using a variable to insert the expression into sed and didn't quote it.

sed -i.bak -r -e "$exp" ~/.zshrc

as per Leon's comment

Appending to file, sed unterminated address regex

With single quotes you don't need to escape $ sign since it's not going to be evaluated by shell.

Either

 sed -e '$a...'

or

sed -e "\$a..."

sed: unterminated address regex

Between single quotes (') the backslashes are interpreted as "real backslashes", so the escape characters are not interpreted".

You can resolve this by simply using a new line without the backslash in the quote environment:

sed -e '/UNCOMMENT THIS/,/jmx/ {
/foo/d
/test/d
}' \
test.txt

As you see, you need to provide a backslash at the end of the command, to ensure test.txt is grouped with the command call. But bash automatically groups content between two single quotes.



Related Topics



Leave a reply



Submit