regex - How to grep exact matching special characters from file? -
i have file below:
a   4   ab,cc,ab,bc b   6   x,xx,y,%,%%,\,\\ ab  0      i need grep special characters third column file , return corresponding first column. e.g., need grep '%' , return me b (it's corresponding first column)
i have tried using:
grep -w "%" file1   but return me % , %% both. like:
b   6   x,xx,y,%,%%,\,\\   where %,%% highlighted. want grep exact word/character searched. in above case should try find '%' , not '%%'. approach works fine words grep manual grep -w works when finds lines containing matches form whole words.
i tried using with
grep -wp "%" file1   for perl pattern. did not return anything.
can suggest how can grep exact matching special characters? not solve problem special characters '\'. backslash can escaped , handled. other special characters need find solution.
ok. slight change required here in question. answers given here great , work according question. maybe missed requirement here. bad. solutions here used '%' test parameter, '%' example. looking more of generalized solution working words/characters. i'll give example. consider file below:
a   4      b,c            c,ab,bc           ^          ^           ^     couple of tabs here       multiple spaces here b   6   x,xx,y,%,%%,\,\\ ab  0    what mean file can contain sort of characters, words (separated single/multiple spaces, tabs, etc.) , special characters (including single quote ('), double quote ("), backslash ()). these 3 needs specially handled kind of reserved.
i apologize missing part before, hope kind of solution looking here clear now.
i vote working solutions special characters. doesn't allow me (less reputation). there general solution? or if can separate words(letters & numbers) , special characters if condition in shell script maybe?
thanks in advance
using perl command line,
perl -ne 'say /(\s+)/ if /%/' file      
Comments
Post a Comment