Issue
I am using this grep command to extract the strings
grep -Enro --exclude=\*features.cc --exclude=\*.h --exclude=\*switches.cc '\bk[A-Z]\w*' ./*
my output is:-
./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:kMinImageCount skia_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
But there are duplicates in the output. The same string is repeating. I want to extract unique strings. could someone guide me through this? thanks in advance.
I need the output as below:
./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
I don't the same string to be repeated.
Solution
grep
has a -m
switch, meaning that you can limit the maximum amount of matches. Using -m 1
should solve your problem, so you would get something like:
grep -Enro -m 1 --exclude=\*features.cc --exclude=\*.h --exclude=\*switches.cc '\bk[A-Z]\w*' ./*
Answered By - Dominique