I need multiple print result in one line

Viewed 77

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 ?

2 Answers

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.

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
Related