Question

In: Computer Science

IN LINUX/UNIX 1. Based on the example “awkc7” introduced in the handouts, please write an awk...

IN LINUX/UNIX

1. Based on the example “awkc7” introduced in the handouts, please write an awk script to display the first six records in “loginfile.” Please test your script to make sure the script displays the following information:

ics325sp200221 pts/6        75.168.197.229   Wed Apr 29 22:09 - 23:27 (01:17)    

ics325sp200221 pts/10       75.168.197.229   Wed Apr 29 22:04 - 22:07 (00:02)    

ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:28 - 15:30 (00:02)    

ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:22 - 15:23 (00:00)    

ics325sp200222 pts/11       68.47.45.2       Wed Apr 29 14:54 - 22:34 (07:39)    

ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 14:52 - 15:08 (00:15)  

2. How to modify “awkc7” so that we can display the last three records in “loginfile?” (you can assume that we have only 7 records in “loginfile”). Please test your script so that it displays the following information:

ics325sp200222 pts/11       68.47.45.2       Wed Apr 29 14:54 - 22:34 (07:39)    

ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 14:52 - 15:08 (00:15)    

ics325sp200221 pts/8        75.168.197.229   Wed Apr 29 14:03 - 22:10 (08:07)

3. Based on the example “awkc7” introduced in the handouts, please write an awk script to display the records from the third to fifth in “loginfile.” Please test your script to make sure the script displays the following information:

ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:28 - 15:30 (00:02)    

ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:22 - 15:23 (00:00)    

ics325sp200222 pts/11       68.47.45.2       Wed Apr 29 14:54 - 22:34 (07:39)       

4. As we know, the command “df –h” will return the following message:

Filesystem      Size Used Avail Use% Mounted on udev            3.9G 4.0K 3.9G   1% /dev tmpfs           799M 800K 798M   1% /run /dev/dm-0        97G   44G   48G 48% / none            4.0K     0 4.0K   0% /sys/fs/cgroup none            5.0M     0 5.0M   0% /run/lock none            3.9G     0 3.9G   0% /run/shm none            100M     0 100M   0% /run/user

/dev/sda1       236M   40M 184M 18% /boot

Please write an awk command to parse the output of “df –h” so that the following information is displayed: (hint: study “awkc8” in the handout and “example 7” in lab 7)

Total Used Disk Space: 44G

5. Based on the examples “awkc8” and “awkc88,” write an awk script called “awkc888” that takes two input values and output the larger one as shown below:

$ ./awkc888 100 40

100

$

$ ./awkc888 100 240

240

$

Solutions

Expert Solution

# Sample data
# @filename ./loginfile.txt

# ics325sp200221 pts/6        75.168.197.229   Wed Apr 29 22:09 - 23:27 (01:17) 
# ics325sp200221 pts/10       75.168.197.229   Wed Apr 29 22:04 - 22:07 (00:02) 
# ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:28 - 15:30 (00:02) 
# ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:22 - 15:23 (00:00)  
# ics325sp200222 pts/11       68.47.45.2       Wed Apr 29 14:54 - 22:34 (07:39)  
# ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 14:52 - 15:08 (00:15)
# ics325sp200221 pts/8        75.168.197.229   Wed Apr 29 14:03 - 22:10 (08:07)

# 1
# Based on the example “awkc7” introduced in the handouts, 
# please write an awk script to display the first six records in “loginfile.” 
# Please test your script to make sure the script displays the following information:
awk '
    NR <= 6 { 
        print $0
    }' ./loginfile.txt

# 2
#  How to modify “awkc7” so that we can display the last three records in “loginfile?” 
#  (you can assume that we have only 7 records in “loginfile”). 
#  Please test your script so that it displays the following information:
awk '{
    for( i=0; i < 2; i++) 
        a[i] = a[i+1];
        a[2] = $0;
    } 
    END {
        print a[0],a[1],a[2];
}' OFS='\n' ./loginfile.txt

# 3
# Based on the example “awkc7” introduced in the handouts, 
# please write an awk script to display the records from the third to fifth in “loginfile.” 
# Please test your script to make sure the script displays the following information:
awk '
    NR >= 3 && NR <= 5 { 
        print $0
    }' ./loginfile.txt


# 4
# As we know, the command “df –h” will return the following message:
# Please write an awk command to parse the output of “df –h” so that the following information is displayed: 
# (hint: study “awkc8” in the handout and “example 7” in lab 7)
df -h ./loginfile.txt |  
    awk '1 < NR {
        print "Total Used Disk Space: " $3;
    }'

# 5
# Based on the examples “awkc8” and “awkc88,” write an awk script called “awkc888” 
# that takes two input values and output the larger one as shown below:
awk 'BEGIN {
        if (ARGV[1] < ARGV[2]) {
            print ARGV[2]
        } else {
            print ARGV[1]
        }
    }' $1 $2

Related Solutions

please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
please use linux or unix to complete, and include pictures of the output. Modify the code...
please use linux or unix to complete, and include pictures of the output. Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will sum up numbers from 801 - 1000 Make main thread wait for other threads to finish execution and sum up all the results. Display the total to the...
PLEASE USE LINUX/UNIX 1.Use either pico, vi, or cat to create the following file and name...
PLEASE USE LINUX/UNIX 1.Use either pico, vi, or cat to create the following file and name it as “mysedfile”: Name Class1 Class2 Class3 Tom 92 94 88 Nancy 91 85 95 Lisa 99 77 96 Jerry 84 98 90 2. Please use sed command(s) to complete the following tasks. display Tom’s record. display Lisa’s record. display both Tom’s and Lisa’s records. remove the blank line(s) from “mysedfile.” replace all the digits with *.
please use linux or unix to complete Diff command The diff command displays differences between two...
please use linux or unix to complete Diff command The diff command displays differences between two files on a line-by-line basis. It displays the differences as instructions that you can use to edit one of the files ( using the vi editor) to make it the same as the other. When you use diff, it produces a series of lines containing Append (a), Delete (d), and Change (c) instructions. Each of these lines is followed by the lines from the...
This is unix based server management Part A Steps in the exercise: Write, and verify the...
This is unix based server management Part A Steps in the exercise: Write, and verify the operation of, an rsync command that will perform a differential backup in place of the copy command. Verify that the rsync process is backing up only the incremental files by running it, then running it again, then adding a new file, and running again. Include the option in rsync to delete any files that do not exist in the destination directory. Verify this by...
Guide to UNIX Using Linux (4th Edition) 1.What is sed? A Stream editor is used to...
Guide to UNIX Using Linux (4th Edition) 1.What is sed? A Stream editor is used to perform basic transformations on text read from a file or a pipe. The result is sent to standard output. The syntax for the sed command has no output file specification, but results can be saved to a file using output redirection. The editor does not modify the original input. What distinguishes sed from other editors, such as vi and ed, is its ability to...
QUESTION 1 Match the following LINUX/UNIX commands with what they do. du    whereis users who...
QUESTION 1 Match the following LINUX/UNIX commands with what they do. du    whereis users who am i A. display a compact list of users currently logged in B. locate the binary, source, and manual page files for a command C. summarize disk usage D. who am i currently logged in as on the Linux server. QUESTION 2 What rm command option (flag) would you use to remove a file that begins with a - (hyphen)? -f -p --   ...
UNIX/LINUX LAB (1) Review the sample shell program (tryShell.c), and compile/run the program (tryShell) with the...
UNIX/LINUX LAB (1) Review the sample shell program (tryShell.c), and compile/run the program (tryShell) with the following commands, and at the end, use CTRL+C to terminate the program: ls ls -l tryShell* date whoami hostname uname -a ctrl+C    (2) Run the program (tryShell) with "time -p" with a few commands: time -p ./tryShell (3) Edit the program (tryShell.c) so that it will exit (terminate the program) when the input command string is "exit" try shell.c code at bottom //////////// #include...
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”....
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”. It takes one or more files and displays requested number of lines from the ending. If number is not specified, then it print 10 lines by default.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT