Question

3.0.3 Questions: Using patterns wtih grep Provide the grep commands for the following searches in the file /usr/share/common-

Using Linux commands grep

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

[1] grep '^[A-Z]' /usr/share/common-licenses/GPL-3

[2]   grep -Po '(?<=\().*?(?=\))' /usr/share/common-licenses/GPL-3

[3] grep '^[A-Z].*\.$' /usr/share/common-licenses/GPL-3

[4] grep 'GPL\|General\sPublic\sLicense' /usr/share/common-licenses/GPL-3


OUTPUT

1.  root@exploitech:-# grep ^[A-Z] /usr/share/common-licenses/GPL-3 GNU General Public License for most of our software; it app

2.  root@exploitech:-# grep - Po (?<=\(.*?(?=)) /usr/share/common-licenses/GPL-3 C i 2 with or without modification i 2 а b ker

3.

root@exploitech:-# grep ^[A-Z].*\.$ /usr/share/common-licenses/GPL-3 Source. License by making exceptions from one or more

4.
root@exploitech:-# grep GPL\| General\sPublic\sLicense /usr/share/common-licenses/GPL-3 The GNU General Public License is a

EXPLANATION


The grep scans a document for a specific pattern of characters, and shows all lines that contain that pattern. The pattern that is looked/searched in the file is called regular expression.

Syntax - grep [options] pattern [files]

[1] grep '^[A-Z]' /usr/share/common-licenses/GPL-3​​​​​​​

The ^ regular expression pattern indicates the beginning of a line. This can be utilized in grep to match the lines which start with the given string or example. In our case we want to get the lines that will start with uppercase letter only. So we used ^[A-Z].

[2]   grep -Po '(?<=\().*?(?=\))' /usr/share/common-licenses/GPL-3
-P option Interpret PATTERN as a Perl regular expression and -o : Print only the matched parts of a matching line
(?<=\().*?(?=\))
​​​​​​​
This will look for the opening bracket ( and then ignores it, then prints all the non-close-parenthesis characters that follow.

[3] grep '^[A-Z].*\.$' /usr/share/common-licenses/GPL-3

We can combine( perform and operation) two regular expression by using .*

^[A-Z]
this will return words start with capital letters

\.$  this will return words end with . (Period)

[4] grep 'GPL\|General\sPublic\sLicense' /usr/share/common-licenses/GPL-3

For or we used \| or operator in regular expression. for space, we used \s regular expression.

Add a comment
Know the answer?
Add Answer to:
Using Linux commands grep 3.0.3 Questions: Using patterns wtih grep Provide the grep commands for the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • These are linux commands. Type cd /usr/share/dict. The file words is the Linux English dictionary. You...

    These are linux commands. Type cd /usr/share/dict. The file words is the Linux English dictionary. You will use egrep to explore this file. Your answers below will be the egrep command that solves the problem. a.List all words that have the letter a followed immediately by the letter z. b.List all words that have the letter a followed sometime later by the letter z (there must be at least one letter in between). c.List all words that start with the...

  • LINUX ubuntu please. Please show the result's screenshot. Thanks in advanced. Using the regular expression rules...

    LINUX ubuntu please. Please show the result's screenshot. Thanks in advanced. Using the regular expression rules create grep commands that locate the following lines in /etc/services: All lines that contain the string smtp. All lines that begin with the string smtp. All lines that include periods (dots, .) All lines that include the string ftp except when that string is followed immediately by a dash (-). All lines in which the letter a follows the letter z. All lines that...

  • Linux commands questions help 1.Find all files under the current directory which ends in '.dat' (just...

    Linux commands questions help 1.Find all files under the current directory which ends in '.dat' (just the .dat not the single quotes as well) and use -exec to create a listing of each file's inode number. 2. Find all files under the /tmp directory whose size is greater than 65 kilobytes and use -exec with an appropriate command to delete these files. 3. Search files in ~ and all subdirectories -- that contain the word 'hawk' (case sensitive) at the...

  • Using a Linux command-line interpreter, show the screenshots for executing the following commands: (1) display the...

    Using a Linux command-line interpreter, show the screenshots for executing the following commands: (1) display the current working directory, (2) list the contents of a directory, (3) change directory, (4) create a directory, (5) clear the screen, (6) copy a file from a directory into another directory, (7) delete a directory, (8) delete a file, (9) report information for a single process or set of processes, and (10) report a real-time statistics for current processes.

  • LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check...

    LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check the output) Display the command(s) used to do the following: create an empty file called history by using just a redirection operator. Verify and show. Show/verify all results (i.e., all commands and their corresponding outputs). Wait 1 minute or more and then display the command(s) used to do the following: change the timestamp on the history file you just created. Verify/display the change. Show/verify...

  • Unix/Linux The purpose of this lab is to practice the commands to manage and organize files...

    Unix/Linux The purpose of this lab is to practice the commands to manage and organize files and directories: How would one go about this? Thanks. Task 1: Preliminaries: 1) If you have not already done so, create a directory called bin under your HOME directory. 2) If you have not already made a copy (using ftp) of the file called famous.dat from the Assignment#1, do that now. 3) Make bin the active/working directory. Task 2: Perform all of the following...

  • Using linux Write one-line New Tab ands that determine and print the following desired output: 1....

    Using linux Write one-line New Tab ands that determine and print the following desired output: 1. The total word count in files file1.txt, file2.txt, and file3.txt combined (assume the three files exist in the current directory) 2. How many user accounts are not allowed to log in to the system. You need to calculate the number of users in file /etc/passwd that include /nologin on their line. 3. The name of the 6 largest files in/usr/bin , while suppressing any...

  • I have to do this question using UNIX commands (or terminal on Apple computers) If you...

    I have to do this question using UNIX commands (or terminal on Apple computers) If you have a data file called datafile(below) Show only line 3 Show only the last line For all lines that have the string key in it change the word more to other Print lines that follow this pattern of four characters: the first letter is an m and the last is a n – the two intervening letters can be anything. Print all lines that...

  • USING Unix/Linux shell !!!: 1) Write a script (project2.sh) that will take information from a file,...

    USING Unix/Linux shell !!!: 1) Write a script (project2.sh) that will take information from a file, and print (user’s choice of printers) identical form letters to each recipient. Either E197, E-199, E-194 printers or to project2.output. Prompt the user for their choice. 2) The script and output file are due: per Moodle timeline. Please upload your fully functioning script (project2.sh) your data file (project2.input) and your output file (project2.output) into Moodle. 3) Requirements of the script. a. You can use...

  • Hi, I need help for solving Linux question. . 1.Using the proper text editor, create a...

    Hi, I need help for solving Linux question. . 1.Using the proper text editor, create a shell file called by (your name), your enrollment number, your program and the courses you study. Use the appropriate variables and display the above to the standard output (screen). . 2. Write A Shell Script to perform the following: Display the files and directories Print the date in 24 hour format Display the System id Display the current working directory Print the status of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT