Question

In: Computer Science

The awk commands to print the first and third words (with a space between) from each...

The awk commands to print the first and third words (with a space between) from each line of the input that has the substring 'cat' in the second word (assume all lines have at least three words). Note, words are fields in this case. Your output should be a copy of each input line with the substring 'cat' in the second word and also, with just the first and third words printed. A series of comments that fully describes your awk commands, including a description of the purpose of each function call, and the arguments to each function.
using the command awk -f quest1.awk input.txt where 'input.txt' is the input file..

Solutions

Expert Solution

Input File(input.txt):

So there are 5 lines with three words separated by space. In which, two of them contain the substring "CAT" in the second word.

Program Output:

Since the Line2 , line4 and line5 only contain the substring CAT in the second word, I displayed the 1st and 3rd words for each of them as suggested by you. Please let me know if you need more help or clarification needed on this task. Also request you to hit the like button if you are satisfied with my answer.

Program code with comments(quest.awk):

#!/usr/bin/awk -f

#Program execution starts from here

BEGIN {

# Reading each line from the input file using getline built-in function and storing the record value to a variable called 'line' with the help of while loop
# Here the value of ARGN[1] = input.txt

while (( getline line <ARGV[1]) >0)
{
# Splitting the current line with space and storing it to an array named 'a'
split(line,a," ");

#Checking whether the second word in the array contains a substring named "cat"
if (a[2]~/cat/)
{

# If there is a substring named 'cat' is present, then print the first and third words for the current line
print ""a[1]" "a[3]""

}

}
}

akhil@akhil-VirtualBox:-/todays cat input.txt line1 dogs birds line2 cats animals line3 animals birds line4 Scats dogs line5 10cat animals

akhil akhil-VirtualBox:-/todays awk -f ./questi.awk input.txt Hine2 animals line4 dogs line5 animals


Related Solutions

Choose 10 commands from the list to study in detail for this assignment. For each command,...
Choose 10 commands from the list to study in detail for this assignment. For each command, you need to provide a short description of the main functionality, and an example run (including output) of the command. Notes  You need to choose at least one command from each category.  Be brief. You do not need to write a lot.  Although you are only required to document the usages of 10 commands in this assignment, you are expected to...
(IN PYTHON 3) Complete the following two tasks: 1. Words like first, second, and third are...
(IN PYTHON 3) Complete the following two tasks: 1. Words like first, second, and third are referred to as ordinal numbers. In this exercise, you will write a function that takes an integer as its only parameter and returns a string containing the appropriate English ordinal number as its only result. Your function must handle the integers between 1 and 12 (inclusive). It should return an empty string if a value outside of this range is provided as a parameter....
Consider the message ‘is he it she is this is it is’. (Include space between each...
Consider the message ‘is he it she is this is it is’. (Include space between each word also as a symbol) Obtain: Binary equivalent of each symbol   Average code length Information content for each symbol Coding efficiency η in %   
(a) From your understanding, when would you use each of the following simulation commands in LTspice?...
(a) From your understanding, when would you use each of the following simulation commands in LTspice? i. DC Operating Point ii. Transient iii. AC Analysis iv. DC Sweep
Design a program that will read each line of text from a file, print it out...
Design a program that will read each line of text from a file, print it out to the screen in forward and reverse order and determine if it is a palindrome, ignoring case, spaces, and punctuation. (A palindrome is a phrase that reads the same both forwards and backwards.) Example program run: A Toyota's a Toyota atoyoT a s'atoyoT A This is a palindrome! Hello World dlroW olleH This is NOT a palindrome! Note: You are only designing the program...
What are the differences between first, second, and third generation CAR-T receptors. Discuss whether the different...
What are the differences between first, second, and third generation CAR-T receptors. Discuss whether the different intracellular domains of the receptors represent signal 1 or signal 2. Typed Answers only, thank you.
17)Here is the set of data from the previous page:10,11,12,13,15,17,17,18,20,20. The first, second, and third quartiles...
17)Here is the set of data from the previous page:10,11,12,13,15,17,17,18,20,20. The first, second, and third quartiles for this data set are 12, 16, and 18 respectively. Identify the 5-number summary for this data set, and create a box plot(box-and-whisker plot) representing it. 18)a) What 3 numbers are cited in the Empirical Rule for normal distributions?(b) Suppose that height for a species of tree is normally distributed with a mean of 30 feet and a standarddeviation of 3 feet. Approximately what...
Define price discrimination. Explain the difference between first-degree and third-degree price discrimination with two examples of...
Define price discrimination. Explain the difference between first-degree and third-degree price discrimination with two examples of each. Your answer will not be complete without two examples of each. Provide your answer here. DO NOT TRY TO COPY/PASTE YOUR ANSWER.
1a.Number of Independent Claims: 1b.Number of Dependent Claims: 1c.In the space below, rewrite the first claim (independent) in your own words:
  1a.Number of Independent Claims: 1b.Number of Dependent Claims: 1c.In the space below, rewrite the first claim (independent) in your own words: What is claimed is:1. A method for treating inflammatory diseases comprising administering to a subject in need of treatment an effective anti-inflammatory amount of a compound of formula I: ##STR3##wherein R.sub.1 is hydrogen or lower alkyl and n is an integer of from 4 to 6, or a pharmaceutically acceptable salt thereof.2. The method of claim 1, wherein...
How are third-generation antipsychotic drugs different than first-generation antipsychotic drugs? Explain the difference between the glutamate...
How are third-generation antipsychotic drugs different than first-generation antipsychotic drugs? Explain the difference between the glutamate hypothesis, dopamine hypothesis, and the serotonin-dopamine hypothesis of psychosis.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT