?
Solved

HELP! search a string with spaces in a file

Posted on 2003-03-07
2
Medium Priority
?
181 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

612 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