I have a file like this:
This is my work
This is my work
This is my WORK
I want to search all patterns irrespective of spaces and upper/lower cases. How can I do this using sed?
I have a file like this:
This is my work
This is my work
This is my WORK
I want to search all patterns irrespective of spaces and upper/lower cases. How can I do this using sed?
You do not need sed
for this. grep
with ignore case and the quantifier *
on each space is more than sufficient.
grep -i 'This *is *my *work' Input.txt
If you insist on sed, you can use this crazy hack from this answer, as shown below.
sed 's/This *is *my *work/&/I;tx;d;:x' Input.txt
You can also use the following variation of jkyako's answer.
sed -n '/This *is *my *work/Ip' Input.txt
Note that if you do not want to match lines that simply contain the pattern, but only lines that match the pattern, you will have to anchor your pattern with ^
and $
.
sed -n '/^This *is *my *work/Ip$' Input1.txt
Sorry I didn't allow for spaces in my original answer. This should solve that problem.
grep -i "this\s*is\s*my\s*work" file
Specifically using sed you could try the following, perhaps there's a shorter way:
sed -n '/[Tt][Hh][Ii][Ss] *[Ii][Ss] *[Mm][Yy] *[Ww][Oo][Rr][Kk]/p'