我有一个包含多个ID的日志文件,如下所示:
INFO: [Synth 8-3491] module 'IOBUF' declared at 'C:/Xilinx/Vivado/2017.3/scripts/rt/data/unisim_comp.v:22655' bound to instance 'LED_tri_iobuf_7' of component 'IOBUF' [C:/.../block_design_wrapper.vhd:342]
INFO: [Synth 8-3491] module 'IOBUF' declared at 'C:/Xilinx/Vivado/2017.3/scripts/rt/data/unisim_comp.v:22655' bound to instance 'MAX11603_I2C_scl_iobuf' of component 'IOBUF' [C:/.../block_design_wrapper.vhd:349]
INFO: [Synth 8-3491] module 'IOBUF' declared at 'C:/Xilinx/Vivado/2017.3/scripts/rt/data/unisim_comp.v:22655' bound to instance 'MAX11603_I2C_sda_iobuf' of component 'IOBUF' [C:/.../block_design_wrapper.vhd:356]
INFO: [Synth 8-3491] module 'block_design' declared at 'C:/Projects/.../block_design.vhd:2346' bound to instance 'block_design_i' of component 'block_design' [C:/.../block_design_wrapper.vhd:363]
---------------------------------------------------------------------------------
Starting RTL Elaboration : Time (s): cpu = 00:00:07 ; elapsed = 00:00:07 . Memory (MB): peak = 491.250 ; gain = 104.844
---------------------------------------------------------------------------------
INFO: [Synth 8-638] synthesizing module 'block_design' [C:/Projects/.../block_design.vhd:2469]
INFO: [Synth 8-638] synthesizing module 'block_design_axi_mem_intercon_0' [C:/Projects/.../block_design.vhd:1403]
INFO: [Synth 8-638] synthesizing module 'm00_couplers_imp_1Y96WCF' [C:/Projects/.../block_design.vhd:81]
INFO: [Synth 8-3491] module 'block_design_auto_pc_0' declared at 'C:/.../block_design_auto_pc_0_stub.vhdl:5' bound to instance 'auto_pc' of component 'block_design_auto_pc_0' [C:/Projects/.../block_design.vhd:267]
INFO: [Synth 8-638] synthesizing module 'block_design_auto_pc_0' [C:/.../block_design_auto_pc_0_stub.vhdl:71]
INFO: [Synth 8-256] done synthesizing module 'm00_couplers_imp_1Y96WCF' (2#1) [C:/Projects/.../block_design.vhd:81]
INFO: [Synth 8-638] synthesizing module 'm01_couplers_imp_1SYGEF3' [C:/Projects/.../block_design.vhd:422]
INFO: [Synth 8-256] done synthesizing module 'm01_couplers_imp_1SYGEF3' (3#1) [C:/Projects/.../block_design.vhd:422]
INFO: [Synth 8-638] synthesizing module 'm02_couplers_imp_1MNJOVZ' [C:/Projects/.../block_design.vhd:611]
每个INFO
行都包含来自特定工具(此处为Synth)和ID xx-yyyy
的消息。
如何使用Bash和Git-Bash中提供的工具提取日志文件中所有出现的ID?最后,我需要将输入日志文件拆分为多个文件,仅包含属于同一ID的邮件。因此,ID列表必须是唯一的。
我在PowerShell中已经完成了相同的脚本编写。此方法使用正则表达式匹配和为每个新ID扩展的ID数组。
它分3个步骤处理日志文件:
主要问题是:如何创建此唯一邮件ID列表?(第2步)
PowerShell脚本:
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$ReportFile
)
$SynthesisLogFile = Get-Item $ReportFile
$SynthesisLog = $SynthesisLogFile.BaseName
$Categories = @("INFO", "CRITICAL WARNING", "WARNING", "ERROR")
foreach ($Cat in $Categories)
{ Write-Host "Extracting category $Cat from $ReportFile ..."
$line=0
cat ".\$ReportFile" | %{ $line=$line+1; if ($_ -match "^$Cat") { "$line`t$_"} } > ".\$SynthesisLog.$Cat.log"
$IDs = @();
cat ".\$SynthesisLog.$Cat.log" | %{ $m = $_ -match "^\d+\t$($Cat): \[(\w+) (\d+-\d+)\]"; $mm = $Matches[2]; if ($IDs -notcontains $mm) {$IDs = $IDs + $mm } }
foreach ($ID in $IDs)
{ Write-Host " Extracting ID: $ID ..."
cat ".\$SynthesisLog.$Cat.log" | Select-String "$ID" > ".\$SynthesisLog.$Cat.$ID.log"
}
}
这是我目前的Bash脚本:
#! /bin/bash
LOGFILE=$(basename "$1")
PREFIX="${LOGFILE%.*}"
for CATEGORY in INFO WARNING "CRITICAL WARNING" ERROR; do
CATEGORY_FILE="$PREFIX.$CATEGORY.log"
echo "Extracting category '$CATEGORY' from '$LOGFILE' ..."
grep -n "^$CATEGORY: " "$1" > "$CATEGORY_FILE"
if [[ -s $CATEGORY_FILE ]]; then
echo " File contains data"
else
echo " Deleting empty output file for category '$CATEGORY'"
rm "$CATEGORY_FILE"
fi
done
以下是我在answer下改进的最终Bash脚本:
#! /bin/bash
LOGFILE=$(basename "$1")
PREFIX="${LOGFILE%.*}"
for CATEGORY in INFO WARNING "CRITICAL WARNING" ERROR; do
CATEGORY_FILE="$PREFIX.$CATEGORY.log"
echo "Extracting category '$CATEGORY' from '$LOGFILE' ..."
grep -n "^$CATEGORY: " "$1" > "$CATEGORY_FILE"
if [[ -s $CATEGORY_FILE ]]; then
for ID in $(grep -P "^\d+:$CATEGORY: \[\w+ \d+-\d+\]" "$CATEGORY_FILE" | awk -F' ' '{print $3}' | tr -d ']' | sort | uniq); do
ID_FILE="$PREFIX.$CATEGORY.$ID.log"
echo " Extracting ID: $ID ..."
grep "$ID" "$CATEGORY_FILE" > "$ID_FILE"
done
else
echo " Deleting empty output file for category '$CATEGORY'"
rm "$CATEGORY_FILE"
fi
done
答案 0 :(得分:1)
试试这个......
$('span fa fa-fw fa-ban').removeClass('span fa fa-fw fa-ban').addClass('span fa fa-fw fa-close');