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
Best Text Search Engine for Integrating with Custom Web App
Analyzing CPU Registers During Kernel Crash Dump
How to Install the Specific Version of Postgres
How to Get Only Filenames Without Path by Using Grep
Cannot Open Libmpfr.So.4 After Update on Ubuntu 18.04
Jenkins to Run Maven Build on Linux or Windows
Python Read Linux Memory Process Error (/Proc/$Pid/Mem)
Automating Linux Ebs Snapshots Backup and Clean-Up
Perf-Report Show Value of CPU Register
Why Does Unitywebrequest Return Unkown Error When I Do a Get Request on Linux
How to Redirect Output of Echo Over Ssh to a File
Docker Container Accessible Only via Cloudflare Cdn (Selected Ip Ranges)
Does the Linux Scheduler Prefer to Run Child Process After Fork()
Bash Scripting - Iterating Through "Variable" Variable Names for a List of Associative Arrays
Is There a Subversion Web Client That I Can Use
How to Build an If Condition in Shell to Check Whether Curl Succeeded