473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with searching files with egrep

Hello, everybody. I have read some examples and manuals for the egrep command for Linux and I don't know if this egrep command is right for the particular files I am searching for. Here is what the question says:

Read documentation about the Unix egrep command. Then,
write an egrep command that will search all files, in the current
directory or any subdirectory (or sub-subdirectory, etc), such that
the file name has a 7 or 8 in the name; and within each such file,
print any line satisfying the following criterion: in the line there is
a word (consisting of entirely alphabetic characters, with no spaces,
quotes, hyphens or digits) that has the following three things, in
this order: (i ) some lower-case letter in the range d through k; (ii )
the letter e or the letter j; and (iii ) the word ends with ion – some
examples are Evangelion, Dandelion, parhelion, triskelion.

I came up with this egrep command:
egrep '([:alpha:].[ion$])|(-v [:punc:][:space:])' "7|8" *.txt

Please tell me if this egrep command is correct or give me suggestions on how to improve it. Thank you.
Nov 2 '07 #1
1 3064
prn
254 Expert 100+
Well, this looks a lot like a homework problem to me, so I'm not going to "answer" your question, but I will give you some hints toward areas where I think you don't understand.

First, reread the section of the egrep man page about what [ and ] do. Then think about the part of your expression including the "[ion$]" Think about what that means. and think about the difference between:
Expand|Select|Wrap|Line Numbers
  1. ion
and
Expand|Select|Wrap|Line Numbers
  1. [ion]
There is a big difference here. (Also remember what "." means in a regular expression!)

Also, don't forget about parts (1) and (2). You don't seem to have covered those in your RE. And recheck what "$" means. It does NOT mean the end of a word it means the end of a line. You will need to rethink how to specify the end of the word.

You also need to rethink how to specify the part about filenames containing a "7" OR an "8" (hint: try using a different command, e.g, ls to find the right set of files) and certainly you will need to make sure you search files in sub (and sub-sub) directories. (Hint: check the "Options" section of the man page for a suitable keyword.)

Finally, I suggest working on all these parts of the problem separately and then putting them together. You have a lot of confusion packed into a single command here. I don't think you're quite ready to solve the whole problem at once. You really need to break it down into steps. Once you have done that, then you can put it back together.

HTH,
Paul
Nov 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of...
49
by: Mark Hahn | last post by:
As we are addressing the "warts" in Python to be fixed in Prothon, we have come upon the mutable default parameter problem. For those unfamiliar with the problem, it can be seen in this Prothon...
4
by: Clarence | last post by:
Hi - I have a problem and here is the verbose version of what I am trying to do (better too much info than not enough). I am searching through about 4,700 XML files containing company contact...
15
by: Uday | last post by:
Hi All, Is there way to list all functions in a C files? I've to rename all the functions. thanks, Uday
0
by: David Berman | last post by:
Hello, I'm receiving an error reading the machine.config file when I try to access my web application. This error came out of nowhere. After searching many sites, googelizing and searching here,...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
1
by: hash | last post by:
Hello! While trying to port VC6 code to VC8, I stuck at this DLL problem. While compiling my project which is DLL, I am getting this error mfcs80d.lib(dllmodul.obj) : error LNK2005:...
4
by: Caldas | last post by:
I'm trying to find files in the current directory that have the occurence of '<IWM_Datasource>NOUID</IWM_Datasource>' AND '<IWM_HasMetaData>true</IWM_HasMetaData>'. I was able to find just the...
7
by: plumb and tree | last post by:
I've been trying for days to build 64 bit python with Solaris 10 + Sun Studio 12. Can anyone helpl please. This is how I tried to do build: # ./configure --prefix=/opt/python2.4...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.