
"input_loan_msisdn.txt"ファイル内の電話番号のリスト(多く)を私のスクリプトへの入力として使用し(ファイルの電話番号は1行ずつリストされています)、私の出力をgrepするキーワードとして使用したいと思います。その他のファイル yemmy_snap*
入力ファイルの例:
2348093700000
2348180000000
2348090000000
2348097000000
2347050000000
2348090000000
2348170000000
以下の私の試みを参照してください。
#!/bin/bash
for msisdn in $(cat input_loan_msisdn.txt); do
cd /onip/cdr/output/snapshot/yemmy/backup
zgrep $msisdn yemmy_snap* | \
awk -F "|" '{print $1 " " $14 " " $4 }' ocs_snapshot*.unl \
> /onip/app/cbpapp/RETURN_LOAN/output_loan_msisdn.txt;
done
答え1
スイッチがあるのでループはwhile
不要です。grep
-f
grep -f input_loan_msisdn.txt yemmy_snap* | <do other stuff with the data>
-f
渡されたファイルどの空の行を引いてgrep
合わせるすべてライン、(次のように動作しますcat
)。渡されたファイルを-f
事前に編集できないと仮定すると、実行時に次のように変更できます。
grep '.' input_loan_msisdn.txt | \
grep -f - yemmy_snap* | <do other stuff with the data>
からman grep
:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. If this option is used
multiple times or is combined with the -e (--regexp) option,
search for all patterns given. The empty file contains zero
patterns, and therefore matches nothing.