The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > BSD
.
google unix.com



BSD BSD, sometimes called Berkeley Unix, is a Unix operating system developed by the Computer Systems Research Group of the UC Berkeley.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep syntax for this... roshanjain2 Shell Programming and Scripting 4 02-19-2007 06:21 AM
Need help with the syntax using awk+grep kthri Shell Programming and Scripting 6 11-07-2005 05:01 AM
Command syntax dsimpg1 UNIX for Dummies Questions & Answers 2 02-17-2005 02:13 PM
command syntax pmap UNIX for Dummies Questions & Answers 3 01-09-2002 11:06 AM
Syntax for tar command baunocj UNIX for Dummies Questions & Answers 1 05-02-2001 10:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2009
Straitsfan Straitsfan is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 41
proper syntax of grep command

I'm learning UNIX on my mac (BSD), using a manual. I'm trying to figure out the grep command, and am getting something wrong. I've opened one of my files in NeoOffice and am looking for a string, the phrase 'I am writing.' I've been to some sites to get the proper syntax, and from what I can see the proper syntax is:

grep "I am writing" [file name]

A lot of times I get the message that no such file or directory exists, even when I think I've entered all the information. When that doesn't happen, the cursor just blinks, with no display of the string I'm looking for. Can someone tell me what I'm missing? Granted, the book i'm using is the OS X missing manual by david pogue, and it's only a few paragraphs on the command, so I may not be comprehending something. Please, if you could write out the proper syntax (including any slashes, dots, etc.) so I can compare it to what I'm doing.
  #2 (permalink)  
Old 02-27-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool

grep will return all lines that contain a searched-for string.
And I have seen some odd results when the lines are not delimited as usually expected with a line-feed at the end of each. So, that is a first thought - that your file is not correctly delimited. (see commands like dos2unix and unix2dos for more on this)
The next issues are capitalization and spacing. The grep command, without additional options, is an exact match. This relates to my comment on spacing as there might be two spaces between certain words, they words may be on separate lines, there could be tab characters between the words.

See the following example:
Code:
> cat file002
this is boring
but I am writing
so we can test
to see that I
am writing
> grep "I am writing" file002
but I am writing
  #3 (permalink)  
Old 02-27-2009
Straitsfan Straitsfan is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 41
Can you explain what you mean by 'delimited?'

I just copied the NeoOffice file (saved as .doc, a word format) to text edit (a .txt file) and the command worked (grep 'I am writing') but it printed the whole letter, or most of it -- which I'm guessing means that it found all the lines with any of the three words in the string and printed those lines. Is it possible to use 'grep' to find this particular sentence fragment and no other lines which don't contain this entire fragment?
  #4 (permalink)  
Old 02-27-2009
TonyLawrence TonyLawrence is offline
Registered User
  
 

Join Date: Sep 2007
Location: SE Mass
Posts: 140
Quote:
Originally Posted by Straitsfan View Post
Can you explain what you mean by 'delimited?'

I just copied the NeoOffice file (saved as .doc, a word format) to text edit (a .txt file) and the command worked (grep 'I am writing') but it printed the whole letter, or most of it -- which I'm guessing means that it found all the lines with any of the three words in the string and printed those lines. Is it possible to use 'grep' to find this particular sentence fragment and no other lines which don't contain this entire fragment?
Copying a .doc to something named .txt does NOT make it a text file.

I think this is the basis of your problem and misunderstanding.

Try doing a "Save As" and choose something that is Text (I don't know what Neo offers you, probably "Text", perhaps some variants).

Grep is designed to work on text files, not wordprocessor files.
  #5 (permalink)  
Old 02-28-2009
Straitsfan Straitsfan is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 41
Smile

I saved it as a txt file (text) in NeoOffice. But the grep command doesn't work. I entered grep "I am writing" then the pathname, ending with the file name (\name\ name\ name\.txt [The file name consists of three letters, with a space between them, no space between the last word and dot) but got the message 'No such file or directory.' when I try it with the copy saved in Apple's Text Edit (the txt extension) application it worked fine.

Can you tell me exactly what is meant by a text file and how it differs from a word processing file? Because I can choose fonts and formatting in Text Edit, just like Word or NeoOffice.

Last edited by Straitsfan; 02-28-2009 at 01:45 PM..
  #6 (permalink)  
Old 03-22-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 730
Put the filename with spaces in it inside speech marks, e.g.:
Code:
$ grep "I am writing" "/home/user/docs/text file.txt"
File names with spaces are best avoided for Unix...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0