gpt4 book ai didi

bash - 如何使用 grep 提取不重复的字符串模式

转载 作者:行者123 更新时间:2023-12-04 19:27:35 28 4
gpt4 key购买 nike

我正在使用这个 grep 命令来提取字符串

grep -Enro --exclude=\*features.cc --exclude=\*.h --exclude=\*switches.cc '\bk[A-Z]\w*' ./*
我的输出是: -

./vulkan/generate_bindings.py:409:kVulkanRequiredApiVersion
./vulkan/generate_bindings.py:588:kVulkanRequiredApiVersion
./vulkan/generate_bindings.py:603:kVulkanRequiredApiVersion
./vulkan/vulkan_instance.cc:24:kSkippedErrors
./vulkan/vulkan_instance.cc:39:kSkippedErrors
./vulkan/vulkan_instance.cc:89:kVulkanRequiredApiVersion
./vulkan/vulkan_instance.cc:95:kVulkanRequiredApiVersion
./vulkan/vulkan_instance.cc:291:kVulkanRequiredApiVersion
./vulkan/vulkan_instance.cc:292:kVulkanRequiredApiVersion
./vulkan/vulkan_surface.cc:27:kPreferredVkFormats
./vulkan/vulkan_surface.cc:32:kPreferredVkFormats
./vulkan/vulkan_surface.cc:79:kMinImageCountskia_bindings/gles2_implementation_with_grcontext_support.cc:324:kVertex_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:327:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:332:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:339:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:343:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:348:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:354:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:361:kStencil_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:364:kPixelStore_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:368:kPixelStore_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:371:kProgram_GrGLBackendState./skia_bindings/gles2_implementation_with_grcontext_support.cc:374:kProgram_GrGLBackendState


但是输出中有重复项。相同的字符串在重复。我想提取唯一的字符串。有人可以指导我吗?提前致谢。
我需要如下输出:

./vulkan/generate_bindings.py:409:kVulkanRequiredApiVersion./vulkan/vulkan_instance.cc:24:kSkippedErrors./vulkan/vulkan_instance.cc:89:kVulkanRequiredApiVersion./vulkan/vulkan_surface.cc:27:kPreferredVkFormats./vulkan/vulkan_surface.cc:79:kMinImageCount./skia_bindings/gles2_implementation_with_grcontext_support.cc:324:kVertex_GrGLBackendState ./skia_bindings/gles2_implementation_with_grcontext_support.cc:339:kStencil_GrGLBackendState


我不重复相同的字符串。

最佳答案

grep有一个 -m开关,这意味着您可以限制匹配的最大数量。使用 -m 1应该解决你的问题,所以你会得到类似的东西:

grep -Enro -m 1 --exclude=\*features.cc --exclude=\*.h --exclude=\*switches.cc '\bk[A-Z]\w*' ./*

关于bash - 如何使用 grep 提取不重复的字符串模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69610698/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com