Question

In: Computer Science

Using egrep and grep in linux Using sentences.txt Find all sentences that have words where there...

Using egrep and grep in linux

  1. Using sentences.txt
    1. Find all sentences that have words where there are two vowels in a row.
    2. Find all sentences that contain punctuation marks other than periods.
    3. Find all sentences that contain punctuation marks, including periods, that are not at the end of the sentence.
    4. Find all sentences that contain at least three words.
    5. Find all sentences that contain exactly four words.
    6. Find all sentences that contain words in which the letters (upper or lower case) a, b, c, and d appear in that order somewhere in the words (not necessarily consecutively). This should, for instance, find “a bat can die”.

What sentences.txt contains:

Anything goes here.

Or not

When, why or how.

A bat can die

The dog never does.

Yikes! he proclaimed

A big can of doo doo is gone.

The zebra never yells at x-rays well unless it is proscribed.

Once upon a time.

Farther. Back down the road!

Yes, a time once did exist

Solutions

Expert Solution

Hello there, hope you're having a good day. Let us start off with a brief of what grep and egrep are. grep is a command-line application or utility to check for patterns of text based on a specific regular expression in a specific line by line data. While egrep achieves the same purpose, it does so in a different way using certain characters as special meta characters.

For the specified questions:

1. grep -e "[aeiou][aeiou]" sentence.txt

The following command is broken down as:

-e specifies we are passing a regular expression

[aeiou][aeiou] marks the actual regular expression where the vowels would repeat.

2. grep -Ei '[[:punct:]]' sentence.txt | grep -Eiv [.]

Here, the Ei mode is used as i ignores case while E runs an extended regex. -v mode inverts matches which only returns unmatched lines. The built-in class [[:punct:]] contains all punctuations.

NB: for "." to be used in egrep, give escape character "\"

3.grep -E '[^[:punct:]]$' sentence.txt

Here, in extended regex mode, the [^] marks non existance of given characters where the characters are punctuations. The $ sign marks the end of the line.

4.grep -P '\w+\s+\w+\s+\w+' sentence.txt

Here, grep is launched in -P perl regex mode for easy searching of words and spaces wherein w+ is a word while s+ marks a spacing.

As the question contains 6 subparts but the student hasn't requested all parts to be answered, I am concluding my answers with that note.

I hope this helped you better understand grep. Thank you have a nice day.


Related Solutions

linux Using the grep or egrep commands, what would be the full command (including regular expression)...
linux Using the grep or egrep commands, what would be the full command (including regular expression) to view only the lines in the file /boot/grub/grub.cfg that DO NOT begin with a hashtag (the # sign). In other words, what would be the command to print all the lines in this file that do not begin with this character.
linux: Regular expressions file name: studentsyslog.txt Use a regular expression and grep or egrep to filter...
linux: Regular expressions file name: studentsyslog.txt Use a regular expression and grep or egrep to filter the file so the output displays only the items requested. Put your full command in the space provided 1.Show only the lines that end with an ellipses (3 dots) :
linux: regular expressions file name: studentsyslog.txt Use a regular expression and grep or egrep to filter...
linux: regular expressions file name: studentsyslog.txt Use a regular expression and grep or egrep to filter the file so the output displays only the items requested. Put your full command in the space provided. 1. Display only the lines that were written to the file between the times of 12:55 and 12:59 (inclusive). This is tricky. Don’t think of these times as numbers, think of these times as a series of characters (a 1 followed-by a 2 followed-by a colon,...
linux: regular expressions file name: studentsyslog.txt Use a regular expression and grep or egrep to filter...
linux: regular expressions file name: studentsyslog.txt Use a regular expression and grep or egrep to filter the file so the output displays only the items requested. Put your full command in the space provided. 1. Display only the lines that were written to the file between the times of 12:55 and 12:59 (inclusive). This is tricky. Don’t think of these times as numbers, think of these times as a series of characters (a 1 followed-by a 2 followed-by a colon,...
In MongoDB using Linux how do you Execute the command to find the size of a...
In MongoDB using Linux how do you Execute the command to find the size of a single document of your choosing from the enron database Execute the command to find the size of the collection of documents in the enron database
here i have a dictionary with the words and i have to find the words with...
here i have a dictionary with the words and i have to find the words with the largest size, (i mean word count for eg abdominohysterectomy) which have anagrams , like for example ,loop -> pool. Also , i have to sort them in alphabetical way so what could be the algorithm for that public class Anagrams {    private static final int MAX_WORD_LENGTH = 25;    private static IArray<IVector<String>> theDictionaries =        new Array<>(MAX_WORD_LENGTH);    public static void...
In Linux Terminal 1. Give a command using find to search from the root directory the...
In Linux Terminal 1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt 2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path) 3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB). 4....
Create by using Linux server • Create a file name it foo.txt • Remove all permissions...
Create by using Linux server • Create a file name it foo.txt • Remove all permissions from foo.txt • What happen if you try to read the file? • Change foo.txt permission to read and write only for owner • Change foo.txt permission to read for group • Change foo.txt permission to read and write everyone
Linux is open source software. Using your own words describe the essence of open-source software and...
Linux is open source software. Using your own words describe the essence of open-source software and how it differs from proprietary software, and explain in detail why one kind of software offers its users a more consistent experience.
Describe in your own words, using full sentences, 3 events that occur in the duodenum of...
Describe in your own words, using full sentences, 3 events that occur in the duodenum of the small intestine to allow this to be the major organ "spot" where digestion occurs. *Hint - what other organs open directly into this space or have ducts that open into this space? 1. 2. 3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT