Kartik Deshpande Kartik Deshpande - 5 months ago 30
Bash Question

Grep to escape special characters

Hello i am new to shell scripting i am facing the following problems

1 > how do i grep to find words with " or ' or both in a word in a file which is large

i tried

grep "'\|"" foo.txt


which does not work

2 > Take one file which consist of a text and print entire lines of another file where that text is present
example

File 1 contains

abc
def
lmo


file 2 contains

amn,abc
abc,amd
fgh,def
abd,lmo


Match the text in file 1 and 2nd column of file 2 and print the entire line of file 2

desired output
amn,abc
fgh,def
abd,lmo

Answer

You can use character classes to match " or ' as

grep "['\"]"

Example

$ echo hello\" | grep "['\"]"
hello"
Comments