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

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

  • Creating a Shell Interface Using Java This project consists of modifying a Java program so that...

    Creating a Shell Interface Using Java This project consists of modifying a Java program so that it serves as a shell interface that accepts user commands and then executes each command in a separate process external to the Java virtual machine. Overview A shell interface provides the user with a prompt, after which the user enters the next command. The example below illustrates the prompt jsh> and the user’s next command: cat Prog.java. This command displays the file Prog.java on...

  • The goal is to create a code for implementing a Columns game using pygame Your program...

    The goal is to create a code for implementing a Columns game using pygame Your program will read its input via the Python shell (i.e., using the built-in input() function), printing no prompts to a user with no extraneous output other than precisely what is specified below. The intent here is not to write a user-friendly user interface; what you're actually doing is building a tool for testing your game mechanics, which we'll then be using to automatically test them....

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
ADVERTISEMENT