有txt文件第一列是姓名,第二列是分数,筛选出及格和不及格的人从高到底排列
shell
#!/bin/bash
sort -n -r -k 2 grade.txt > grade_sort.txt
awk '{if($2<60) print $0}' grade_sort.txt > fail.txt
awk '{if($2>=60) print $0}' grade_sort.txt > pass.txt
tcl
set name {}
set grade {}
set fp [open grade.txt r]
while {[gets $fp line]!=-1} {
set list1 [split "$line"]
puts $list1
lappend name [lindex $list1 0]
lappend grade [lindex $list1 end]
}
puts $name
puts $grade
set newgrade [lsort -integer -decreasing $grade]
puts $newgrade
#set length [llength $newgrade]
#i=0
#while {[$i < $length]} {
#incr i
#}
close $fp
以下为程序运行结果: