我面臨一個問題,我的檔案每次都有不同的行數,它以 sqlldr 輸出結尾,顯示匯出到檔案的行數
40968 rows selected.
由于這個檔案將被下一個行程拾取,我想去掉這個額外的文本。所以我想出了這樣的想法:
# Remove exported record count from end of file
remove_count=$(( $(wc -l < ${output_dir}/file.dat)-3 1 ))
echo "Removing extra lines from spooled file"
sed '$remove_count, $ d' file.dat >> file.dat
問題是似乎sed
不能使用變數作為應該開始洗掉的行數。我找不到更好的解決方案。有什么我可以做得更好或有人看到錯誤的地方嗎?提前致謝!
uj5u.com熱心網友回復:
你不需要這么復雜的解決方案;head
可以這樣做:
$ echo -e 'first\nsecond\nthird\nfourth' | head -n-3
first
參見手冊:
-n, --lines=[-]NUM
print the first NUM lines instead of the first 10; with the
leading '-', print all but the last NUM lines of each file
uj5u.com熱心網友回復:
sed
可以包括變數擴展。
這是正確bash
參考的問題。
'
防止bash
字串中的任何擴展。
"
允許bash
字串中的所有擴展。
建議嘗試:
# Remove exported record count from end of file
remove_count=$(( $(wc -l < ${output_dir}/file.dat)-3 1 ))
echo "Removing extra lines from spooled file"
sed -i "$remove_count, \$ d" file.dat
uj5u.com熱心網友回復:
這可能對您有用(GNU sed):
sed '1N;N;$d;P;D' file
這將洗掉檔案的最后 3 行。
程式化版本將是:
sed ':a;N;s/[^\n]*/&/3;Ta;d$;P;D' file
where3
可以是檔案末尾的任意數量的行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/482062.html
標籤:重击 Unix sed sql-loader 厕所