?
Solved

Linux: Find files containing text regardless of dashes

Posted on 2014-03-31
6
Medium Priority
?
380 Views
Last Modified: 2014-04-01
Running Linux, how can I find all files containing specific text, disregarding dashes?

For example:
grep -iwr "hello-world" /my/dir/

Open in new window

That should find a file that contains this:
Hello World
?

Also, I only need the filename.  I do not want content from the file.

Thanks!
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 2000 total points
ID: 39967065
It slightly depends on what you are looking for.  If you want any single character between the "hello" and the "world", use a dot (so "hello.world")  - dot matches any character - that would match "hello world", "hello-world", or even "hello%world".

If you want a specific set of allowed characters, use something like "hello[- _]world", to allow hyphen, space or underscore (in this example).  Normally a hyphen in a character class like that (i.e. between "[" and "]") would indicate a range of values (e..g "[A-Z]" means all of the upper-case letters), but at the start or end of the class (next to the "[" or "]") it matches a hyphen.

To get just the names, add the "-l" flag to your "-iwr".
0
 
LVL 30

Expert Comment

by:serialband
ID: 39967349
If you want to match capitals and lower case you'd do the following

grep -liwr [Hh]ello.[Ww]orld  /my/dir/

If you want it to match the space character, you either quote the string or escape the space
grep -liwr "[Hh]ello [Ww]orld"  /my/dir/
grep -liwr [Hh]ello\ [Ww]orld  /my/dir/
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39967407
(there's a -i in the options, so case is ignored anyway)
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 30

Expert Comment

by:serialband
ID: 39967766
Yes, I saw that, yet I continued posting.  :P
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39967905
How are you deriving your search string?
0
 
LVL 3

Expert Comment

by:Kevin Pham
ID: 39969907
Why would you want to add a dash to the text string... then write a script to strip it? Just do this

$ grep -Ril 'hello world' /my/dir

This will look recursively to find the words and only display the filenames.
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question