Reputation: 23
I have a problem with awk...
awk -F "|" '{ print $1;split($5,a,".") ; print a[1] }' test > awk_test
This command is right but the result is :
serveur1
7
serveur2
7
But I would like
serveur1 7
serveur2 7
Can you help me please ?
Upvotes: 2
Views: 219
Reputation: 133518
Based on your shown attempts please try following.
awk -F "|" '{ sub(/\..*/,"",$5); print $1,$5 }' Input_file
Explanation: Simply making field separator as |
, then substituting from DOT to everything to NULL in 5th field. Then printing 1st and 5th field. Basically why its giving in new line because you are using 2 times print statement here.
Upvotes: 1
Reputation: 2761
Without knowing the input data and just to fix the output formatting, you need:
awk -F "|" '{ split($5, a, "."); print $1, a[1] }' test > awk_test
Upvotes: 1