shell - How to add a new line to a file and match the indentation from prev line -


i have:

globalweather:     name: 'globalweather:1.0.0' 

i tried: sed -i '' "s/^\( *\)name: '$api_name'$/&\n\1\$ref: $1/" $2

but i'm getting:

globalweather:     name: 'globalweather:1.0.0'n    $ref: globalweather_1.0.0.yaml  

i want:

globalweather:    $ref: globalweather_1.0.0.yaml  

can me on i'm missing?

you can capture indention , use substitution insert it:

sed 's/^\( *\)something$/&\n\1something else/' 

breakdown:

s/   ^      # start of string   \( *\) # capture 0 or more spaces     $      # end of string /   &      # full matched string   \1     # captured spaces   else / 

but there might more elegant solution after command.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -