Linux 在跨多行的模式之后,如何在文件中插入一行

Linux 在跨多行的模式之后,如何在文件中插入一行,linux,bash,shell,unix,Linux,Bash,Shell,Unix,我想在第一次使用bash显示此模式之后插入一行。我该怎么做呢?我想尝试使用该模式匹配位置/{*} location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncommen

我想在第一次使用bash显示此模式之后插入一行。我该怎么做呢?我想尝试使用该模式匹配位置/{*}

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
我希望它变成

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
    location /hbnb_static

感谢您的帮助。

我尝试了Perl one liner:

perl -e '$s.=$_ while <>; $s=~s|location / \{.*?\}|$&\n    location /hbnb_static|s; print $s' inputfile

在bash中也可以这样做吗?
#!/bin/bash
perl -e '$s.=$_ while <>; $s=~s|location / \{.*?\}|$&\n    location /hbnb_static|s; print $s' $1