私のシェルスクリプトには次のforループがあります。
#!bin/ksh
touch output.dat
IFS=">>>"
i=0
for stm in `grep "cpdctl dsjob run-pipeline --project " input_file`
do
echo "the current stmt is : $stm"
done
私の入力ファイルに入力ファイルパターンに一致するレコードが2つあります。だから私は出力が次のようになると期待します
----Expected output
the current stmt is : "first line matching pattern"
the current stmt is : "second line matching pattern"
---Actual output
the current stmt is : "first line matching pattern"
"second line matching pattern"
the current stmt is :
実際の出力から欠落している
私が何を見逃しているのか教えてもらえますか? AWKも試しましたが、出力は同じです。検索してみましたが、似たような質問が見つかりませんでした。
[編集] 今はそうかもしれないと思いました。IFS=">>>>""わかりました。この問題がある可能性があります。したがって、私の完全なコードが含まれています。追加しましたIFS=">>>>""私のレコードには空白文字が含まれているため、forループは空白文字を別々の行として返します。
ベストアンサー1
使用awk
:
awk '/cpdctl dsjob run-pipeline --project / {print "the current stmt is :", $0}' input
これにより、以下を含むすべての行が印刷されます。cpdctl dsjob run-pipeline --project