Help with using different types of GREP

  1. The problem statement, all variables and given/known data:

Hey there, I'm brand new to using Unix as I just started a course on it in my University, and I currently working through a worksheet which focuses on the many commands and methods of GREP (I'm working through the terminal command line in Unix). Currently I am confused with using Grep and vi in the same command. Here is what the question describes.

I found out that by using -i in the command that it will search for words even if they have different upper case/lower case differences, as long as they are correctly spelt the same. However as it mentions in j, it asks for me to correct the spelling error using vi, and I am unsure about how to use this method, or at least how to use it with GREP anyway as I have use gvip (I believe it was) in a past worksheet.

  1. Relevant commands, code, scripts, algorithms:
    To complete i, I simply used the code grep -i Peugeot carslist.txt to find any word matching 'Peugeot', despite the differences in upper/lower case lettering.

  2. The attempts at a solution (include all code and scripts):
    As I just mentioned I have previously used the code grep -i Peugeot carslist.txt to show all the words matching Peugeot despite the differences in upper & lower case letters, but I am unsure as to how vi is involved with changing any cases in the word to upper/lower.

  3. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    Aberystwyth University, West Wales, Adrian Shaw, CS10110 - Introduction To Computer Hardware, Operating Systems, And Unix Tools

Also once this problem is 'hopefully solved' I may be posting more in this thread about any other GREP related issues I am having with my work. Hopefully I am allowed to do this, but if not I can always create new threads about it. If I need to include anything else with my question just say and I will make sure to do so. Hopefully I didn't do anything wrong in asking these questions and that someone will be able to help me with my concerns. =-)

I would guess (j) wants you to describe how to search in vi (or how go to a specific line, if you've supplied the 'line number' option to grep), and then how to manually edit it.

Alternatively, you could just do a search/replace in vi (or even outside vi, e.g. with sed) using a regular expression.

1 Like

Or is it not in relation with the search pattern facility incorporated in vi?
from vi man pages ( type man vi

Truly, if you are willing to learn UNIX even a minimum then it is far from being a waste of time learning vi basics (I installed a vi on my DOS pc at the time... and am completely lost when there is no vi...).
So start by reading the man pages and come back here for more explanation
There are plenty options in vi... even using s ( like sed...) for substitution...

1 Like

Thanks for the help guys, both of you gave me very useful tips, I found that CarloM's method worked wonders for me.

Now however I am having trouble finding values using GREP now, will I need to stop a new thread with the similar format as I did here, or can I just post my question here, still in the same format or even just regular perhaps?

Since its general usage in relation with the above, just continue here for now... Open a new thread if it is more a new topic.

Well if its alright then I may as well as them. I'm curently working through the same worksheet only I have moved onto advanced grep, and there are two questions in it that have me puzzled. Here they are.

And just to show you the layout of how the car list looks like, here are the first few lines, not all of them just in case it seems like too much.

Even with the hints for m & n I'm still having trouble with what comands I should be using, all I know is that I have been using a format such as this for the most recent questions and answers.

or something similar anyway. Some more help on these would be greatfully appreciated. =-)

What version of UNIX are you working on?
You know you can:

grep <pattern> <filename>

(cat superfluous )

I think I'm working on Soralis, Minted/Wiked if either of these words mean anything to you, but the type of questions I'm working through right now with this basic method, or am I wrong in saying that?

Bump? I'm still in need of help with my latest questions, and pretty soon if its not too much trouble.

To check in on solaris:

 uname -sr 

What have you managed so far?
e.g.

grep '.*:[10]:*:*:*$' carslist.txt

Explain to me what the above code is supposed to do.

I'm not sure I undrstand what you mean by 'what I've managed' sorry. :confused:

And yeah, in that code I am trying to find all the car models which include digits within their name. Each .* is a seperate column in the layout from the text file, and the second column is the model, which is what I have labeled [10] with.

Hopefully I explained this without much confusion.

For question m, try this:

#! /bin/sh
while read x
do
    echo $x | cut -d: -f2 | grep -E "[^e]e{2}[^e]" # Assuming 2nd column is car model name
    # The above line will print only those car model names with two e's 
done < carnames.txt