Tag Info

New answers tagged

12

Here is the processing: a[$0]: look at the value of key $0, in associative array a. If it does not exist, create it. a[$0]++: increment the value of a[$0], return the old value as value of expression. If a[$0] does not exist, return 0 and increment a[$0] to 1 (++ operator returns numeric value). !a[$0]++: negate the value of expression. If a[$0]++ return ...


12

Let's see, !a[$0]++ first a[$0] we look at the value of a[$0] (array a with whole input line ($0) as key). If it does not exist ( ! is negation in test will eval to true) !a[$0] we print the input line $0 (default action). Also, we add one ( ++ ) to a[$0], so next time !a[$0] will evaluate to false. Nice, find!! You should have a look at code ...


0

Thank you for your detailed responses Letizia. I used bits and pieces of your code and some of your code, in turn, gave me more ideas. Just to not leave this post hanging: my final (gruesome) code ended up like this: cat sections/sem092 | sort -k 2 | awk '{ print $2 }' | uniq -c > no3 paste instructors | awk '{ print $2 " " $3 }' > no3n ...


1

Save output of your command: cat sections/sem092 | sort -k 2 | awk '{ print $2 }' | uniq -c > firstPart.txt Save this line in file searchInstructorName.sh: cat $1 | while read line; do instructorID=`echo $line | awk '{print $2}'` name=`grep $instructorID instructorList | awk '{print $2 " " $4}'` echo "$line $name" done This script ...



Top 50 recent answers are included