Could anyone help me with the following question, if I have two colums (names and frequency) as follows in a file called name.txt
Michael 1
Jones 1
Ben 2
Rebeca 4
David 1
and I want to use bash script called freqnames.sh that takes one argument (name) and the output should be the ALPHABETICALLY ORDERED list of all name's with the same frequency (popularity) as measured in the second column of the file.
For example.
./name.txt David
will return a list of three names (on separate lines) David, Jones, Michael,which have frequency 1.
Here is what I have tried so far but I don't know what else to add:
Thanks guys, But I would like to do it with grep only no awk. I tried another code shown below and I got an error saying that " line 2: a: command not found"