0

I have an output which is of the format

weight:121p height:6f money:5 update:8 read:62b query:132 etc

I want the output to be without the units like

weight:121 height:6 money:5 update:8 read:62 query:132 etc

I tried | tr "p", " " etc but the problem is it removes every occurrence of the letter p in the output.

I only want to remove the units after the colon. What is the best way to go about solving this issue?

mtk
  • 13,221
  • 16
  • 72
  • 112

4 Answers4

3
sed 's/\(:[0-9][0-9]*\)[a-z]/\1/g'

or if the units might be longer than one letter

sed 's/\(:[0-9][0-9]*\)[a-z][a-z]*/\1/g'
Mark Reed
  • 91,912
  • 16
  • 138
  • 175
0
echo "weight:121p height:6f money:5 update:8 read:62b query:132 etc"|awk '{$1=substr($1,0,length($1)-1);$2=substr($2,0,length($2)-1);$5=substr($5,0,length($5)-1);print}'

        weight:121 height:6 money:5 update:8 read:62 query:132 etc
Vijay
  • 65,327
  • 90
  • 227
  • 319
0

If you prefer perl:

echo "weight:121p height:6f money:5 update:8 read:62b query:132" \
| perl -pe 's/(\w+:\d+)\w* /$1 /g'
memnoch_proxy
  • 1,944
  • 15
  • 20
0

This coerces numbers with trailing non-digits/non-dots into numbers.

awk '{for (i = 1; i <= NF; i++) {split($i, a, /:/); if (a[2] ~ /^[[:digit:]]/) {$i = a[1] ":" a[2] + 0}}; print}' inputfile
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439