Help with using different types of GREP


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with using different types of GREP
# 1  
Old 11-24-2011
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.

Quote:
i) When the data was input into the carslist.txt file, the data input clerk made an error with the CAPS LOCK key, when entering details about a “Peugeot” car. How could you use the grep command to find all types of “Peugeot” cars irrespective of the data input clerk's error?

j) Using the command you've found in i), identify the incorrect record in the file, and appropriately correct the record affected using vi.
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.

2. 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.

3. 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.

4. 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. =-)
# 2  
Old 11-24-2011
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.
This User Gave Thanks to CarloM For This Post:
# 3  
Old 11-24-2011
Or is it not in relation with the search pattern facility incorporated in vi?
from vi man pages ( type man vi
Quote:
/ Read a string from the last line on the screen,
interpret it as a regular expression, and scan
forward for the next occurrence of a matching string.
The search begins when the user types a carriage
return to terminate the pattern; the search can be
terminated by sending SIGINT (or the user-designated
interrupt character).
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...
This User Gave Thanks to vbe For This Post:
# 4  
Old 11-24-2011
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?
# 5  
Old 11-25-2011
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.
# 6  
Old 11-25-2011
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.

Quote:
j) Find out which models of car do NOT contain a digit within their name. Where (line position) within the file are the cars which do have digits within their model name?

m) Find any car model names which include “ee”, without explicitly including “ee”
within your search pattern. Hint: Use curly { } brackets

n) Find out all car models beginning with “B”, and redirect these to a file called
“alpha-carslist.txt”. Append to this file, all car models beginning with “C”. How
many records are in the above file? (Hint: use the “wc -l” command)
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.

Quote:
Ford:Mondeo:1997:Blue:5
Vauxhall:Vectra:1999:White:2
Seat:Ibiza:1996:Red:4
Peugeot:406:1999:Silver:1
McLaren:F1:1997:Black:2
Skoda:Octavia:2003:Silver:2
Peugeot:206:2000:Red:1
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.

Quote:
cat carslist.txt | grep '.*:.*:.*:.*:.*$'
or something similar anyway. Some more help on these would be greatfully appreciated. =-)
# 7  
Old 11-25-2011
What version of UNIX are you working on?
You know you can:
Code:
grep <pattern> <filename>

(cat superfluous )
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Recursive grep with only certain types of files

Can I please have some ideas on how to do a recursive grep with certain types of files? The file types I want to use are *.c and *.java. I know this normally works with all files. grep -riI 'scanner' /home/bob/ 2>/dev/null Just not sure how to get it to work *.c and *.java files. (5 Replies)
Discussion started by: cokedude
5 Replies

2. Shell Programming and Scripting

Cp -r except certain file types

the following excludes certain directories successfully cp -r probe/!(dir) /destination I want to exclude certain file types and tried unsuccessfully cp -r probe/!(*.avi) /destination (2 Replies)
Discussion started by: tmf
2 Replies

3. What is on Your Mind?

What Types of Food Do You Like The Most?

On another simple topic, multiple choice answers OK ( you can pick more than one or suggest others - we will add your suggestions to the poll ). What Types of Food Do You Like The Most? (27 Replies)
Discussion started by: Neo
27 Replies

4. Programming

enumeration types in C

If I want to declare an array of structures in C and have the number of items in that array to correspond to the items of an enumeration, is there a way to access the maximum value in the enumeration when declaring the array? For instance: typedef struct { various fields.... } ... (3 Replies)
Discussion started by: cleopard
3 Replies

5. UNIX for Dummies Questions & Answers

How do I grep in specific file types?

I have a directory with file types ending .log, .mml, .gll, .dll . How can I grep expressions only in say the .log files? (3 Replies)
Discussion started by: bbbngowc
3 Replies

6. UNIX for Dummies Questions & Answers

mime types

Hi, I am trying to launch an ogg movie from a pdf file which has been produced with pdflatex and \movie {\centerline{\includegraphics {grafiques_xerrades/un_manolo_amb_camera.pdf}}} {hlims_xerrades/XocCumuls.ogg} The switch "externalviewer" makes kpdf launch the default... (5 Replies)
Discussion started by: pau
5 Replies

7. UNIX for Dummies Questions & Answers

Two types of pipes?

What is the difference between: cd /tmp tar -cf - *.txt |gzip > tmp_txt.tar.gz and cd /tmp mknod pipe p gzip < pipe > /tmp/tmp_txt1.tar.gz & tar -cf pipe *.txt Apart from the fact that we have to create the pipe file manually, is there any difference in the performance of the two?... (5 Replies)
Discussion started by: blowtorch
5 Replies

8. UNIX for Dummies Questions & Answers

backup types

can anyone explain me difference between tar and ufsdump commands.............and also i wd like to know the difference between incremental and differential backup......... thx in advance (1 Reply)
Discussion started by: girish_shukla
1 Replies
Login or Register to Ask a Question