Why do I get the white space before and after the delimiter in the following example?
awk -F'^' '{print $1,":",$2}' SERVER_2012-02-29-12-15-00
3969 : 1272
3969 : 1272
3969 : 1272
I expect the results as below without any space:
3969:1272
3969:1272
3969:1272
The text file looks like this...
cat SERVER_2012-02-29-12-15-00
3969^1272^14.140.90.242^^IN^como^2012-02-29
3969^1272^14.140.90.242^^IN^como^2012-02-29
3969^1272^14.140.90.242^^IN^como^2012-02-29
This might work for you:
awk -F'^' '{print $1":"$2}' SERVER_2012-02-29-12-15-00
3969:1272
3969:1272
3969:1272
To concatenate the fields with a :
remove the ,
's.
Or change the output field separator OFS
to null.
awk -F'^' -vOFS='' '{print $1",:,"$2}' SERVER_2012-02-29-12-15-00
3969:1272
3969:1272
3969:1272
Solutions have been given, but no complete explanation...
It is because when you use print
with many parameters (separated by coma) it puts a Field Separator between the values. From the awk
man:
print expr-list
Print expressions. Each expression is separated by the value of the OFS variable. The output record is terminated with the value of the ORS variable.
The string concatenation operator in awk
is not coma, neither +
, but space: str = str1 str2
concatenate str1
and str2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With