awkスクリプトを実行します。しかし、ここにあります。これはコマンドですawk -f awk_scr ERR.txt
。
BEGIN {
FS=" "
target="missing"
}
{
for (i=1; i <= NR; i++) {
for(j=1; j <= NF; j++) {
if ($j == target) {
do {
printf $j > "final.txt"
} while (j == NF)
}
if (j == NF) {
printf "\n"
}
}
}
}
内容はERR.txt
ここにあります。このawkスクリプトは、一致するコンテンツをトリミングするために使用されます。「失われた」その後、ファイルに印刷し、最終結果.txt。
npm ERR! peer dep missing: react@^15.0.0, required by [email protected]
npm ERR! peer dep missing: [email protected] - 3, required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
npm ERR! missing: [email protected], required by [email protected]
ただし、コマンドを実行すると空の標準出力のみが表示されます。
================内容を追加=================
ほんの数分しかかかりませんでしたが、それが私が期待していたものです。とにかく、awkスクリプトは今後も使い続ける価値があります。
missing: react@^15.0.0, required by [email protected]
missing: [email protected] - 3, required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
missing: [email protected], required by [email protected]
ベストアンサー1
# awk_scr
BEGIN {
# clear the output file if it already exists
# you can do this using your shell instead
ORS = ""
print "" > "final.txt"
ORS = "\n"
}
/missing/ {
# delete all characters prior to the last occurrence of "missing:"
# this assumes that there is only one sub-string "missing:" per line
sub(/.*missing:/, "missing:", $0)
# append the updated line to the output file
print $0 >> "final.txt"
}
それからawk -f awk_scr ERR.txt && cat final.txt
。
sed
別の解決策は、より短いものを使用することです。
sed 's/^.*missing:/missing:/' ERR.txt | tee final.txt
しかし、awkソリューションと同じ欠点があります。つまり、「missing:」が 1 行に 1 回だけ発生すると仮定します。どちらも貪欲にawk
似合うからだsed
。
遅延マッチングをシミュレートするには、次のようにします(より良い)。
sed -E 's/(missing)(.*)|./\1\2/g' ERR.txt | tee final.txt