我有2个文件list.txt和fail.txt。它是一个测试用例列表和失败的测试用例。我需要在list.txt中的fail.txt中出现的测试用例上标记失败。我在shell中需要它
答案 0 :(得分:2)
也许您应该调查join
命令?
sed 's/$/ FAIL/' fail.txt |
join -a 1 -e PASS -j 1 -o 1.1,2.2 list.txt -
/work/supernova/alpha/net-nsf.c
/work/supernova/alpha/net-nsf.h
/work/supernova/alpha/nsfpipe.c
/work/supernova/alpha/sqcrypto.c
/work/supernova/alpha/sqlmutil.c
/work/supernova/alpha/squtil.c
/work/supernova/beta/scb.h
/work/supernova/delta/delta-init.c
/work/supernova/delta/delta-pseudo.c
/work/supernova/delta/onvproc.c
/work/supernova/gamma/mt-aio.c
/work/supernova/gamma/mt-aio.h
/work/supernova/gamma/mtblk.c
/work/supernova/gamma/mt.c
/work/supernova/gamma/mtdll.c
/work/supernova/gamma/mt.h
/work/supernova/gamma/mt-info.c
/work/supernova/gamma/mtm.h
/work/supernova/gamma/mtpool.c
/work/supernova/gamma/mtpseudo.c
/work/supernova/gamma/session.c
/work/supernova/gamma/session.h
/work/supernova/omega/jlm.c
/work/supernova/omega/osenv.c
/work/supernova/omicron/mivp.c
/work/supernova/alpha/net-nsf.c
/work/supernova/alpha/net-nsf.h
/work/supernova/alpha/sqcrypto.c
/work/supernova/beta/scb.h
/work/supernova/delta/delta-init.c
/work/supernova/delta/delta-pseudo.c
/work/supernova/gamma/mt-aio.c
/work/supernova/gamma/mt-aio.h
/work/supernova/gamma/mtblk.c
/work/supernova/gamma/mt-info.c
/work/supernova/gamma/mtpool.c
/work/supernova/gamma/session.h
/work/supernova/omega/jlm.c
/work/supernova/alpha/net-nsf.c FAIL
/work/supernova/alpha/net-nsf.h FAIL
/work/supernova/alpha/nsfpipe.c PASS
/work/supernova/alpha/sqcrypto.c FAIL
/work/supernova/alpha/sqlmutil.c PASS
/work/supernova/alpha/squtil.c PASS
/work/supernova/beta/scb.h FAIL
/work/supernova/delta/delta-init.c FAIL
/work/supernova/delta/delta-pseudo.c FAIL
/work/supernova/delta/onvproc.c PASS
/work/supernova/gamma/mt-aio.c FAIL
/work/supernova/gamma/mt-aio.h FAIL
/work/supernova/gamma/mtblk.c FAIL
/work/supernova/gamma/mt.c PASS
/work/supernova/gamma/mtdll.c PASS
/work/supernova/gamma/mt.h PASS
/work/supernova/gamma/mt-info.c FAIL
/work/supernova/gamma/mtm.h PASS
/work/supernova/gamma/mtpool.c FAIL
/work/supernova/gamma/mtpseudo.c PASS
/work/supernova/gamma/session.c PASS
/work/supernova/gamma/session.h FAIL
/work/supernova/omega/jlm.c FAIL
/work/supernova/omega/osenv.c PASS
/work/supernova/omicron/mivp.c PASS
只要文件按排序顺序,就应该像魅力一样工作。如果您不想要PASS标记,则省略-e PASS
参数对。如果您需要其他FAIL标记,请调整sed
脚本。如果您想要输出列的不同顺序,请更改-o
选项。
答案 1 :(得分:1)
您可能希望使用grep
及其-f
和-v
选项
grep -v -f file1 file2
grep -v -f file2 file1
答案 2 :(得分:0)
没有你分享你的文件格式,这是一个猜测:
awk '
NR == FNR {failed[$1]; next}
($1 in failed) {print "failed: " $0; next}
1
' fail.txt list.txt > marked.txt
更新
awk '
NR == FNR {failed[$1]; next}
{
status = ($1 in failed) ? "Fail" : "Pass"
print $0, status
}
' fail.txt list.txt > marked.txt