以下代码应该逐行打印sourceFile的内容到targetFile,每行都在前面的无线键s:',但它只打印'无线-key s:'到targetFile。
#!/bin/bash
sourceFile="file1.log"
targetFile="/etc/network/interfaces"
numLines="$(wc -l < "${sourceFile}")"
counter=5
lineNumber=5
if (( counter >= "$numLines" )) || [[ ! -f "${sourceFile}" ]]; then
echo "invaild file" >82; exit 1
fi
while [ "$counter" -le "$numLines" ]; do
sed -i "${lineNumber} s/.*/wireless-key s: $(sed -n ${counter}p <<< " ${sourceFile}")/" "${targetFile}"
counter=$((counter + 1))
done
谢谢
答案 0 :(得分:0)
也许是一种不同的方法......
awk'{print NR,“wireless_key”,$ 0}'srcfile&gt; dstfile