0
考慮下面的代碼匹配:模式使用可變在SED
pattern="*.some_pattern.*"
orignalLogFile='sample.log'
outputFile='1.txt'
temp='1.log'
# match the pattern and replace with a new line
sed 's/'$pattern'/\n/' $orignalLogFile > $temp
拋出
'的sed:-e表達#1,炭9:未結束`s' 的命令」
如何解決此問題?
直接使用模式,而沒有在一個變量中工作正常。 sed需要替換換行符 sed's /.* patterntomatch。*/\ n /'sample.log> newLog.txt 這工作正常。問題是當我有一個變量「patterntomatch」。 – user170008
這可能適用於Linux中的GNU sed,是的;但這不符合POSIX標準,因此不便攜。我給你的解決方案適用於FreeBSD,因此是便攜式的;它將與OSX以及任何其他UNIX一起工作。 GNU公用事業有擴展打破了POSIX標準;這是爲什麼我不在Linux下編寫腳本的一個重要原因。 此外,你可以解決變量不能使用sed,把它放在雙引號而不是單個引號中,就像我在那裏。 – petrus4