0

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?

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
user3635140
  • 13
  • 2
  • 3

3 Answers3

2

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
Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329
0

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
John C
  • 4,276
  • 2
  • 17
  • 28
0

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'
jkyako
  • 616
  • 4
  • 6