regex - Read variable matched by a .* operation -


modified working solution:

sed -r "s/(\.*)\[/\1\r[/g" 

better solution:

sed -r "s/(.*)\[/\1\r[/g" 

broken down:

s/ (\.*)\[    -string capture followed [ / \1\r[      -line replace /g"   believe subsequent strings, more of these made (\.*) in same order appear left right, variables referenced. 

please try keep answers working sed line description of replace operation.

i want learn how use variables in sed. if have solution, i'm ears, wish learn how manipulate variables in sed.

i've tried

$1, %1 , 1

as combination of these \$1, \%1 \1 , /$1 /%1 /1

to no avail.

here's starting working script replaces matching section blank section.

sed -e "s/\.*\[//g" testfile.txt 

what want script replace (* representing prior (nonwhitespace) string)

*[  

with (no blank lines or tabs in-between either)

* [ 

so figured like

c:\temp>sed -e "s/\.*\[/\1/g" testfile.txt sed: -e expression #1, char 12: invalid reference \1 on `s' command's rhs 

i think want this:

$ cat file.txt  should first line*[and should second $ sed -r 's/([^*]*\*)/\1\n/' file.txt  should first line* [and should second 

note using -r option means don't need escape parens. if don't use -r must replace ( \( , ) \) first capture group within first parens

([^*]*\*) 

which captures before (and including) first *.

the replacement (\1\n) prints first capture group, followed newline, followed rest of line.

and if you're interested in learning sed, check out this tutorial


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -