コードスニペットを持つfileAがあります。特定のパターンの後に、そのスニペットをfileBの行に挿入するスクリプトが必要です。あるファイルから別のファイルの特定の場所にコードを挿入するBashスクリプト?
私はaccepted answer in this thread仕事をしようとしてんだけど、そうではありませんし、そうわからないエラーが示されるのはなぜいないされていません。
sed -e '/pattern/r text2insert' filewithpattern
任意の提案を?
パターン(後行に挿入スニペット):
def boot {
も試みエスケープパターンが、運:
def\ boot\ {
def\ boot\ \{
FILEAスニペット:
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))
FILEB(Boot.scala ):
package bootstrap.liftweb
import net.liftweb._
import util._
import Helpers._
import common._
import http._
import sitemap._
import Loc._
/**
* A class that's instantiated early and run. It allows the application
* to modify lift's environment
*/
class Boot {
def boot {
// where to search snippet
LiftRules.addToPackages("code")
// Build SiteMap
val entries = List(
Menu.i("Home")/"index", // the simple way to declare a menu
// more complex because this menu allows anything in the
// /static path to be visible
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))
// set the sitemap. Note if you don't want access control for
// each page, just comment this line out.
LiftRules.setSiteMap(SiteMap(entries:_*))
// Use jQuery 1.4
LiftRules.jsArtifacts = net.liftweb.http.js.jquery.JQuery14Artifacts
//Show the spinny image when an Ajax call starts
LiftRules.ajaxStart =
Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
// Make the spinny image go away when it ends
LiftRules.ajaxEnd =
Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
// Force the request to be UTF-8
LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
}
}
本当にありがとうございます。問題がどこにあるかを見るためにfilewithpatternをビルドしようとしています。 – Kurtosis
sedコマンドのdef boot {'をハードコーディングから変数$ PATTERNまたは$ {PATTERN}に置き換えることに変わりました。パターンは変更されないのでハードコードすることができますが、スクリプトの上部にある変数に他の変数を設定するといいでしょう。任意のアイデアはどのようにsedのparamで正しく評価するvarを取得するには? – Kurtosis
コードを投稿すると、私は見ていきます。おそらく、これはbash変数の引用問題です。 – joelparkerhenderson