y******8 发帖数: 40 | 1 File “abcd” is a space-delimited file, and contains the following columns
of information:
Column 1: Name. Column 2: 1 - took test, 0 - didn’t. Column 3: Score.
Column 4: Date.
Contents of file “abcd”:
TED 1 75.5 01/01/2000
TED 1 80.1 01/02/2000
TED 0 00.0 01/03/2000
TED 1 45.5 01/04/2000
TED 1 94.7 01/05/2000
JON 1 88.1 01/01/2000
JON 1 65.1 01/02/2000
JON 0 00.0 01/03/2000
Contents of file “xyz”:
MOST PASSED TESTS
We want to find out who took the most tests with a grade of 50 or more.
Walk me through the following set of unix commands and tell me what the
result of the output should be at each step.
cat abcd | awk '$2==1 && $3>50 {print $1}' | \
sort | uniq -c | \
sort -n -r | \
head -1| \
awk '{print $2}' >> xyz
请问:下面的输出结果是什么啊?
Step 1:
cat abcd | awk '$2==1 && $3>50 {print $1}'
Output of Step 1:
Step 2: sort | uniq -c
Output of Step 2:
Step 3: sort –n –r
Output of Step 3:
Step 4: head -1
Output of Step 4:
Step 5: awk '{print $2}' >> xyz
Contents of xyz:
Solve the following problems using some combination of the commands:
cat, awk, sort, uniq, head.
Your approach should follow patterns similar to the previous problem.
1. Use file abcd to report each student with the maximum number of tests that they have taken. Results should be:
4 TED
2 JON
ANSWER:
2. Do the same as #1, but format the results to:
TED 4
JON 2
ANSWER:
3. Report the lowest test score of the tests that were taken, and the person who made it. Results should be:
TED 45.5
ANSWER:
4. Report the dates that any tests were taken. Results should be:
01/01/2000
01/02/2000
01/04/2000
01/05/2000
ANSWER:
|
|