473,657 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with searching files with egrep

1 New Member
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 3072
prn
254 Recognized Expert Contributor
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
2523
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 users, supposedly) to upload their files to their designaged directories (max 15 files for each user). A super user (can be more than one) want to search for a particular file name and also a particular textual part of a file of all user's files in all...
49
2593
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 code sample where newbies expect the two function calls below to both print : def f( list= ): print list.append!(1) f() # prints
4
1967
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 details. In the company details are phone numbers. The phone numbers with the formats I need have the following structure. <xs:complexType name="PHONENO"> <xs:sequence maxOccurs="unbounded"> <xs:element name="COUNTRY" type="xs:string"/>
15
9447
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
2726
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, I've found others with the same problem but no resolution. The problem for me (and for others) came out of nowhere. Here's the error message: >>>>> START <<<<< Server Error in '/MyApp' Application....
2
4442
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 */ #include <time.h>
1
3716
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: _DllMain@12 already defined in MSVCRTD.lib(dllmain.obj) I then explicitly added mfc80d.dll to the ignore list and it compiled successfully. But while executing, I get the error that MFC80D.DLL is missing as obvious. I am not getting where am I goin wrong....
4
1414
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 first text like this: find . -name '*Base*xml' -type f -exec egrep -l ^.*'<IWM_Datasource>NOUID</IWM_Datasource>'$ {} /dev/null \; But when I try to add the second text I don't seem to get it right, can any1 help? Regards,
7
4344
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 --without-gcc --enable-shared checking MACHDEP... sunos5 checking EXTRAPLATDIR...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.