Question

“awk” can be used to process simple tables. Given a table below: npu29:yinglir>cat table.txt 1 2...

“awk” can be used to process simple tables. Given a table below:

npu29:yinglir>cat table.txt

1 2 3
2 3 4
5 6 7
3 6 9
2 3 4
3 4 1

The simple command below can be used to filter the table:

npu29:yinglir>cat table.txt | awk ' { if (($3 >= 3) && ($3 <= 4)) print $0 } '

1 2 3
2 3 4
2 3 4

You can also write a simple c-shell script as below. The c-shell script will take the arguments and pass the min and max to awk. See below on how it works:

npu29:yinglir>use_awk.csh

Usage: use_awk.csh file_name min max

npu29:yinglir>use_awk.csh table.txt 3 4

print out lines with column 3 between 3 and 4

1 2 3
2 3 4
2 3 4

npu29:yinglir>use_awk.csh table.txt 4 7

print out lines with column 3 between 4 and 7

2 3 4
5 6 7
2 3 4

              npu29:yinglir>

What to turn in:

1.      Your script
2.      Sample run log on a different table you created.

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

SCRIPT:

#! /bin/csh -f

if ($#argv != 3) then
echo "Usage: use_awk.csh file_name min max"
exit 0
endif

set file_name=$1
set min=$2
set max=$3

echo "print out lines with column 3 between $min and $max"
cat $file_name | awk ' { if (($3 >= '$min') && ($3 <= '$max')) print $0 } '

OUTPUT :

% ./use_awk.csh
Usage: use_awk.csh file_name min max

% ./use_awk.csh table.txt 3 4
print out lines with column 3 between 3 and 4
1 2 3
2 3 4
2 3 4

% ./use_awk.csh table.txt 1 2
print out lines with column 3 between 1 and 2
3 4 1

% ./use_awk.csh table.txt -1 0
print out lines with column 3 between -1 and 0

SCREENSHOT :

#1 /bin/csh -f if ($#argv !- ) then echo Usage: use_awk.csh file_name min max exit θ endif set file_name $1 set min $2 set

Add a comment
Know the answer?
Add Answer to:
“awk” can be used to process simple tables. Given a table below: npu29:yinglir>cat table.txt 1 2...
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
  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • QUESTION 1 From YOUR home directory, execute a find command string that will locate the file...

    QUESTION 1 From YOUR home directory, execute a find command string that will locate the file called resolv.conf. Include the -exec flag in the find command to cat the file to the screen. Begin your find search from the letc directory Select the correct find command string below that will accomplish this. find /etc-name 'resolv.conf -cat D find /etc-name 'resolv.conf -exec cat 0 find. -name 'resolv.conf -exec cat 0\ find /-name 'resolv.conf' -exec cat 0 QUESTION 2 What find command...

  • For this Linux script, answer the questions following it: # Sort lines 7 - 26 of...

    For this Linux script, answer the questions following it: # Sort lines 7 - 26 of the file BEGIN { idx = 1; while (getline line<"makefile" ) { data[idx] = line; idx++; } for (idx2 = 7; idx2 <= 26; idx2++) { data2[idx2 - 6] = data[idx2]; } count = asort(data2); for (idx3 = 1; idx3 < 7; idx3++) { print data[idx3]; } for (idx3 = 1; idx3 <= 20; idx3++) { print data2[idx3]; } for (idx3 = 27; idx3...

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

  • write a script named word_counts.sh that prints out how many words are on each line of...

    write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of words at the end. The script should take no arguments. Instead, the script must work by reading every line of standard input (using a while loop) and counting the number of words on each line separately. The script is intended to work with standard input coming from a pipe, which will most often come from...

  • 1. Write 4 simple shell scripts. Each question will ask you to write one or more...

    1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...

  • Writing Unix Utilities in C (not C++ or C#) my-cat The program my-cat is a simple...

    Writing Unix Utilities in C (not C++ or C#) my-cat The program my-cat is a simple program. Generally, it reads a file as specified by the user and prints its contents. A typical usage is as follows, in which the user wants to see the contents of my-cat.c, and thus types: prompt> ./my-cat my-cat.c #include <stdio.h> ... As shown, my-cat reads the file my-cat.c and prints out its contents. The "./" before the my-cat above is a UNIX thing; it...

  • Fill out the table for the knapsack problem, where the objects, weights, and values are as given, and the overall weight limit is 10 Next, circle the entries in the table that are used when backtrack...

    Fill out the table for the knapsack problem, where the objects, weights, and values are as given, and the overall weight limit is 10 Next, circle the entries in the table that are used when backtracking to find objects to use in the solution Then list the object numbers that can be used for an optimal solution .Also list the weights and values of those objects Verify that the values of your solution objects add up to the optimal number...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

  • Table 3-11 Assume that Max and Min can switch between producing mittens and producing hats at...

    Table 3-11 Assume that Max and Min can switch between producing mittens and producing hats at a constant rate. Quantity Produced in 36 Hours Labor Hours Needed to Make 1 Hats Mittens Hats Mittens Max 18 Min Refer to Table 3-11. Which of the following points would not be on Max's production possibilities frontier, based on a 36-hour production period? a. (6 mittens, 4 hats) b. (2 mittens, 6 hats) C. (18 mittens, 0 hats) d. (12 mittens, 2 hats)

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