[Solved] AWK beginner script

med89med

New Member
Credits
62
Hello ,

I have my file adresse.txt
gwenael | 0298452223| 0638431234 | 50
marcel | 0466442312 | 0638453211 | 31
judith |0154674487 | 0645227937 | 23

and my script awk
#!/bin/sh
awk 'BEGIN {print "On vérifie les numéros de téléphone"; FS="|"}
$2 !/^[0-9][0-9]*$/ {print "Erreur sur le numéro de téléphone domicile,ligne n°"NR": \n"$0}
$3 !/^[0-9][0-9]*$/ {print"Erreur sur le numéro de téléphone du portable,ligne n°"NR": \n"$0}
END {print "Vérification terminé"} ' adresse.txt

And when i lunch it , i have :

"
On vérifie les numéros de téléphone
Erreur sur le numéro de téléphone domicile,ligne n°1:
gwenael |1|0638431234| 50
Erreur sur le numéro de téléphone du portable,ligne n°1:
gwenael |1|0638431234| 50
Erreur sur le numéro de téléphone domicile,ligne n°2:
marcel | 0466442312 | 0638453211 | 31
Erreur sur le numéro de téléphone du portable,ligne n°2:
marcel | 0466442312 | 0638453211 | 31
Vérification terminé
"
Why the numbers of phones are in error , since 0638431234 match with regex ^[0-9][0-9]*$

Thnaks for help
 


wizardfromoz

Administrator
Staff member
Gold Supporter
Credits
18,240
That is good news @med89med and a late welcome to linux.org :)

I am moving this Thread to Command Line, which is where scripting questions are answered, and if you have more scripting questions you can ask them there.

Be prepared to translate the French.

Note the change in venue @KGIII

Chris Turner
wizardfromoz

BTW @med89med that userid make me think of Club Med. :)
 

JasKinasis

Well-Known Member
Credits
7,670
Sorry I'm a little bit late to the party. I was unavailable over the weekend. I take it the OP resolved this themselves? Their answer looks like it's correct.
In awk ~ means "matches", so !~ means "does not match".
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Latest posts

Top