?
Solved

HELP! search a string with spaces in a file

Posted on 2003-03-07
2
Medium Priority
?
178 Views
Last Modified: 2010-04-21
I want to do a search of a string with sed, the search is done in many files specified already and this string can have spaces.  I cant do it with grep because it does not take spaces for the search, this is my code:

read string
read filename
grep $string $filename

the problem is that I need to make it possible to enter more thatn just one filename...

Can someone please help?
Thanx in advance
0
Comment
Question by:nika_anna
[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
2 Comments
 
LVL 2

Accepted Solution

by:
jimbb earned 200 total points
ID: 8094323
You can use spaces for the search string, just surround it with quotes.

grep " " filename

or in your case:

grep "$string" $filename


Or you could escape the space:

grep \  $filename
      ^space

but that's a little uglier.


If you really wanted to use sed, you could do the following:

$ sed -n '/ /p' /etc/passwd
0
 

Author Comment

by:nika_anna
ID: 8100094
Thanx a lot...
I does work now! I would have had to work around the prob, thnx again!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

762 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