Home > Blockchain >  how to extract the string pattern without duplicate using grep
how to extract the string pattern without duplicate using grep

Time:10-19

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

But there are duplicates in the output. I want to extract unique strings. could someone guide me through this? thanks in advance.

CodePudding user response:

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*' ./*
  • Related