Create two files with id as common field. The name of the files are listNum and
ID: 3782208 • Letter: C
Question
Create two files with id as common field. The name of the files are listNum and namelnfo as follows. The first file has id and phone number and the second file has name and id. So id-1 has the phone number 408-392-3194 as shown in file listNum. In file namelnfo the name Johnson has id-1. Therefore, the given phone number is the phone number for Johnson. -sh-4.1$ cat listNum 1:408-392-3194 3:925-234-2112 2:344-5323 -sh-4.1$ First sort the two common fields: -sh-4.1$ cat namelnfo Mortezaie:3 Johnson:1 David: 2 -sh-4.1$ Sort both files based on the id (common field) -sh-4.1$ sort -t:-k 1 listNum -o listNum -sh-4.1$ sort -t: -1c 2 namelnfo Johnson:1 David: 2 Mortezaie:3 -sh-4.1$ sort -t: -k 2 namelnfo -o namelnfo -sh-4.1$ cat namelnfo Johnson:1 David:2 Mortezaie:3 |-sh-4.1$ Then join the two files using the join command. Notice that one file will be created that has all the fields of both files. You can now do processing on this joined file. -sh-4.1$ join -11-22 listNum namelnfo -sh-4.1$ join -1 1 -2 2 -t: listNum namelnfo 1:408-392-3194:Johnson 2:344-5323:David 3:925-234-2112:Mortezaie -sh-4.1$ When you join the two files, redirect result to another file called combine. What command do you use to find the phone number for David? What command do you use to list all the last names with id greater than 2? What command do you use to check if all phone numbers are valid?Explanation / Answer
Here is the step by step process
1)First create the file listNum using the cat listNUm command and write the content of your file
2)same create the file nameInfo using the cat nameInfo command and write the content of your file
3)Then sort the file sort -t: -k 1 listNUm -o listNum as mentioned in question
4)Then sort the file sort -t: -k 1 nameInfo -o nameInfo
4)join them and redirect the result into another file combine using join -1 1 -2 2 -t:listNum nameInfo >combine
5)if above does not works then try this
6)To find phone number for david
7)awk -F '-' '{if ($1 > 2) print $3}' for answer of 6
8)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.