One file “annuaire.txt” have the following addresses under the following format : Surname - Name - date of birth(3 inputs) - Sex - phone number According to the above format, you need to test these seven parameters(empty, ok or not)... (The file is supposed very long with some error as in this file) Georges TARTEMPION 12 2 1967 M 038898422524 Hortense HYABLANT 7 4 1944 F 0146872556 Adrien DUBOUCHON 27 11 1938 M 0154896372 Ludwig SCHMILLBLEERCK 28 12 1957 M 0258459887 Antonio VAVILDA 16 5 1937 M Hughes CARPETTE 8 11 1958 M 0123568629 Il ya trop de ligne dans ce fichier Dagobert ELOY 14 7 1947 M 0225415487 ligne vide Anatole SUISSE 1 2 1965 n 4 Antonino SZWPRESWKY 16 5 8937 M 0298358745 Program D: Write a program using Linux shell script using Grep / awk commands to : • Delete the line 7 “Il ya trop de ligne dans ce fichier” and line 9 “ligne vide” in the file and store in a new .txt file • Find out the name of people without phone number and delete the lines without phone numbers • Find out the phone number that are not correct(The phone number should be exactly 10 number )
时间: 2023-12-03 07:45:45 浏览: 110
statut.annuaire-entreprises.data.gouv.fr:企业家资格反批复
Here's a possible solution using grep and awk:
1. To delete lines 7 and 9 and store the result in a new file:
```
grep -v -e "Il ya trop de ligne dans ce fichier" -e "ligne vide" annuaire.txt > new_annuaire.txt
```
This command uses `grep` to remove lines 7 and 9 from `annuaire.txt` and writes the result to a new file called `new_annuaire.txt`.
2. To find out the names of people without phone numbers and delete those lines:
```
awk '$NF !~ /^[0-9]{10}$/ {print $2 " " $1}' new_annuaire.txt > no_phone.txt
grep -v -f <(cut -d' ' -f1,2 no_phone.txt) new_annuaire.txt > temp.txt
mv temp.txt new_annuaire.txt
```
The first command uses `awk` to print the names of people whose phone number (the last column, `$NF`) does not match the pattern of 10 digits. The result is written to a new file called `no_phone.txt`.
The second command uses `grep` with the `-f` option to read the list of names from `no_phone.txt` and remove those lines from `new_annuaire.txt`. The result is written to a temporary file called `temp.txt`.
The third command renames `temp.txt` to `new_annuaire.txt`.
3. To find out the phone numbers that are not correct:
```
awk '$NF !~ /^[0-9]{10}$/ {print $NF}' new_annuaire.txt
```
This command uses `awk` to print the phone numbers (the last column, `$NF`) that do not match the pattern of 10 digits.
阅读全文