[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
 


I'll ping @JasKinasis for you.

(I do some tolerable scripting, but he's much more adept/advanced than I am.)
 
ok , i have found te problem
expression !/expression régulière/ {instructions} is not working
but this working expression !~ /expression régulière/
 
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. :)
 
I hope those aren't real phone numbers but made up?
 
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".
 
Yeah, I'm pretty sure they fixed it before you got the ping. Thanks, however!

I should probably mark this as solved, as the OP indicated they'd found a resolution.
 

Members online


Top