Modified working solution:
sed -r "s/(\.*)\[/\1\r[/g"
Better solution:
sed -r "s/(.*)\[/\1\r[/g"
Broken down:
s/
(\.*)\[ -String to Capture followed by [
/
\1\r[ -Line to replace with
/g"
I believe for subsequent strings, more of these are made
(\.*) but in the same order they appear from left to right, the variables are referenced.
Please try to keep answers as a working sed line with a description of the replace operation.
I actually do want to learn how to use variables in sed. So if you have another solution, I'm all ears, but I really do wish to learn how to manipulate variables in sed.
I've tried
$1, %1 and 1
as a combination of these \$1, \%1 \1 and /$1 /%1 /1
to no avail.
Here's my starting working script that replaces the matching section with a blank section.
sed -e "s/\.*\[//g" testfile.txt
What I want to do with the script is replace (* representing any prior (nonwhitespace) string)
*[
with (no blank lines or tabs in-between either)
*
[
So I figured something like
C:\temp>sed -e "s/\.*\[/\1/g" testfile.txt
sed: -e expression #1, char 12: invalid reference \1 on `s' command's RHS