Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

one entry in the on database is:

LPE-1*story#1/1 of pearl#1/2*historia de la perla*storia della perla* histoire de la perle* história da pérola*istoria perlei*TOPIC

The fields are separated by stars, *. They are:

sentence ID|English NP|Spanish translation|Italian translation|French translation|Portuguese translation|Romanian translation|Semantic relation

The English NP field has the following format:

noun1#sense/i [preposition] noun2#sense/j

where i and j can be either 1 or 2 indicating the position of the semantic argument in the NP instance (note that the preposition might be missing). For example, in the NP instance chair#1/2 arm#1/1 which encodes a part-whole relation (P-W), the noun chair indicates the whole (and thus is labeled as 2), and the noun arm encoded the part (and is labeled as 1).


Write a shell script containing a combination of UNIX and AWK commands that will give the answer to the following questions. The shell script should be executed only once and output (to standard output, unless mentioned otherwise):

  1. the number of English NP instances in the file;
  2. the number of unique English NPs (consider for this the entire field $2);
  3. the list of unique semantic relations considered in this database (store it in "sr.uniq.txt");
  4. the frequency of each semantic relation in the database with the following format: Semantic_relation frequency (store this in "sr-freq.txt");

How to do for question 2,3,4

share|improve this question
Is this a homework assignment? What have you tried so far? – Paul Oct 11 '13 at 4:43
awk has associative arrays, and the keys in an associative array will be unique. – glenn jackman Oct 11 '13 at 21:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.