我想从源文件中提取提及.sv或.v文件路径的字符串,并将它们存储在数组中。
示例源文件:
#!/bin/csh
vlogan -sverilog -xzy ../common/compil_xyz/displayer.sv ../common/compil_BC/bridge.v ../common/compil_fgh/core.v ../common/compil_mno/counter.v
vlogan -xzy -sverilog ../common/compil_rty/top_wrapp1.v
vcs -o simv_${app} ${VBH_LKJ_FLAGS} -sverilog XfgKL
预期输出数组:
out[0] : ../common/compil_xyz/displayer.sv
out[1] : ../common/compil_BC/bridge.v
out[2] : ../common/compil_fgh/core.v
out[3] : ../common/compil_mno/counter.v
out[4] : ../common/compil_rty/top_wrapp1.v
答案 0 :(得分:1)
您可以使用grep -o
:
set arr = ( `grep -Eo '[^[:blank:]]+\.(sv|v)\b' file | sed 's~^~/~'` )
printf '%s\n' $arr
<强>输出:强>
/../common/compil_xyz/displayer.sv
/../common/compil_BC/bridge.v
/../common/compil_fgh/core.v
/../common/compil_mno/counter.v
/../common/compil_rty/top_wrapp1.v