我正在使用macOS Sierra,它有bash版本3.2.57(1)-release。我希望使用shasum -c /files.txt > /out.txt
验证文件的校验和,其中files.txt
包含校验和,out.txt
是保存结果的位置。
我想要做的是以某种方式使用grep过滤掉并仅将错误保存到out.txt
。这怎么可能? $?
可以派上用场吗?
由于
其他信息:
--BEGIN /file.txt CONTENTS--
865f34fe7ba81e1337ddbdfc511547d190367bbf3dad21aeb6da3eec621044f5 /samplefile.good
93ddaab2f672ff976756f50677646cafebabe93244f615e687db01399cf3fbc6 /samplefile.bad
--END /file.txt CONTENTS--
--BEGIN USER INTERACTION--
$ shasum -c file.txt
/samplefile.good: OK
/samplefile.bad: FAILED
shasum: WARNING: 1 computed checksum did NOT match
$ shasum -c file.txt 2> errors.txt
/samplefile.good: OK
/samplefile.bad: FAILED
$ cat errors.txt
shasum: WARNING: 1 computed checksum did NOT match
$ shasum -c file.txt 2>&1 > errors.txt
shasum: WARNING: 1 computed checksum did NOT match
$ cat errors.txt
/samplefile.good: OK
/samplefile.bad: FAILED
--END USER INTERACTION--
这就是我想要的:
$ cat errors.txt
/samplefile.bad: FAILED
或
$ cat errors.txt
/samplefile.bad: FAILED
shasum: WARNING: 1 computed checksum did NOT match
答案 0 :(得分:0)
您无需使用grep
从shasum
命令中获取各种错误:
$ shasum -c file.txt 2> errors.txt
$ cat error.txt
shasum: file.txt: no properly formatted SHA1 checksum lines found
但是如果你真的想要捕捉到某些错误,你确实可以使用grep
:
$ shasum -c file.txt 2>&1 | grep -i "no properly formatted" > errors.txt