我試圖在第二行使用perl的文本文件插入新行。但它一直在失敗。通過Perl在文本文件中插入一行失敗
我正在使用下面的命令來實現相同。
perl -ni -e "print; print \"permissibleCars = [ ${part[*]} ]\n\" if $. == 2" query/containerId_count.js
但我不斷收到錯誤: -
[email protected]:~/mongosearch# distinct_array=`sed ':a;N;$!ba;s/\n/ /g' output/ontainerId_distinct.txt`
[email protected]:~/mongosearch# declare -a arr=($distinct_array)
[email protected]:~/mongosearch# batchsize=1
[email protected]:~/mongosearch# IFS=,
[email protected]:~/mongosearch# part=("${arr[@]:i:batchsize}")
[email protected]:~/mongosearch# echo $part
"C:00000092666270:53882159774"
[email protected]:~/mongosearch# perl -ni -e "print; print \"permissibleCars = [ ${part[*]} ]\n\" if $. == 2" query/containerId_count.js
Bareword found where operator expected at -e line 1, near ""permissibleCars = [ "C"
(Missing operator before C?)
String found where operator expected at -e line 1, near "53882159774" ]\n""
(Missing operator before " ]\n"?)
syntax error at -e line 1, near ""permissibleCars = [ "C"
Illegal octal digit '9' at -e line 1, at end of line
Execution of -e aborted due to compilation errors.
你能幫我一樣嗎?
問候
試過,但它沒有奏效: - 無法在EOF之前的任何位置找到字符串終止符'''-e第1行。 – user2854333
>>'perl -ni -e'print ;打印「permissibleCars = [\ $ {part [*]}] \ n」如果$。== 2'' –
這不會給出錯誤,但它不會複製存儲在變量中的數據,而是複製permissibleCars = [$ {part – user2854333