[Solved] AWK beginner script

med89med

New Member
Joined
Apr 4, 2021
Messages
5
Reaction score
3
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
 


OP
M

med89med

New Member
Joined
Apr 4, 2021
Messages
5
Reaction score
3
Credits
62
ok , i have found te problem
expression !/expression régulière/ {instructions} is not working
but this working expression !~ /expression régulière/
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
6,604
Reaction score
5,360
Credits
19,459
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. :)
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
3,860
Reaction score
2,611
Credits
27,911
I hope those aren't real phone numbers but made up?
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,317
Reaction score
1,867
Credits
8,257
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


Top