Please give the thumbs up, if it is helpful for you. Thank you!!
Ans c)
Print the second last field of each line in the file:
awk -F '{print $(NF-1)}' lines
The sum of all ages:
awk 'if(length($3) > 0) {n += $3}; END{print n}' names
Total number of lines in the file:
In general, wc -l <filename> will give total number of lines in the file. If you want to do this using awk, use
awk '{print NR}' lines | tail -1
If you only want to use awk, do
awk 'BEGIN{i=0}{i++;}END{print i}' lines
swap first and third column:
awk -F, '{ print $3 "\\" $1 }' switch.txt
also can be done using sed command:
sed 's/^\(.*\),\(.*\)$/\3\\\1/g' switch.txt
In a linux command line Give AWK commands for accomplishing each of the following: Print the...
Write a linux command that will add a "#" character to the start of every line that does not already start with a "#" character. Write a linux command that will append all lines of the /etc/passwd file that contain the word "STUDENT" to the end of the file. Write a linux command that will move the last word of each line to the start of the line. Write a linux command that will add the line number to the...
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...
LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...
Revision Question 3 on Linux. Please explain the shell script commands in the context of post execution. You have just logged in and have a directory called "novel" in your home directory containing the following files: chapter1.docx chapter2.docx chapter3.docx draft.pdf save where "save" is itself a directory and contains the files Attributes.txt draft.pdf.1 draft.pdf.2 draft.pdf.3 indexA.txt indexB.txt list1.txt list2.txt a) Describe the results you would expect when executing the following shell commands: i) ls novel/save/*A* ii) ls novel/*r[23]* iii) rmdir...
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...
Write a program Adder.java that calculates and prints the sum of command line parameters, so if you make the command line parameters be 2 5 22 then the program prints 29. Write a program ShowFiles.java that assumes the command line parameters are each a text file name directly readable by the program. For each file named, print out the three heading lines in the format shown, and then each line of the file contents. If file q.txt contains What is...
Write Linux command for each question. Please use one single commend to do following process. Q1: Display all lines of list1.txt and list2.txt containing the letter ‘p', and sort the result. Q2: Append “file1.txt” and “file2.txt”, and redirect to “file3.txt”. Q3: Sort “file3.txt”, and redirect the result to file “file4.txt” Q4: Use shorthand way to change the permission of “file3.txt” to “user - write read execute, group - read execute, other - execute”. Q5: Extract first column from “file3.txt”, and...
JAVA DATA STRUCTURES Write a line-based text editor. The command syntax is similar to the Unix line editor ed. The internal copy of the file is maintained as a linked list of lines. To be able to go up and down in the file, you have to maintain a doubly linked list. Most commands are represented by a one-character string. Some are two characters and require an argument (or two). Support the commands shown below: Command Function Go to the...
AWK Programming - Please show new working code with screenshot please. Save the following data in a file named teamlist.txt: Name,Team,First Test, Second Test, Third Test Tom,Red,5,17,22 Joe,Green,3,14,22 Maria,Blue,6,18,21 Fred,Blue,2,15,23 Carlos,Red,-1,15,24 Phuong,Green,7,19,21 Enrique,Green,3,16,20 Nancy,Red,9,12,24 Write an AWK script that will compute the average score for every person in the list, the average score for each test, and the average score for each team. If a score is negative, that means the person missed the test, and the score must not...
Linux/Fedora: Write the commands required for the following tasks. Try out each command on your system to ensure that it is correct: a. Make a hierarchical directory structure under /root that consists of one directory containing three subdirectories. b. Copy two files into each of the subdirectories. c. Create one more directory with three subdirectories beneath it and move files from the subdirectories containing them to the counterparts you just created. After you have completed these three steps at the...