-2

I have time like this 14:21:49

Now I need to remove the : from the timestamp which means output should become like this 142149

Input:
  scan_utc_input_time="14:21:49"
Output:
  scan_utc_output_time="142149
0stone0
  • 34,288
  • 4
  • 39
  • 64
Bala Krishna
  • 47
  • 2
  • 8

2 Answers2

1

With tr:

echo "14:21:49" | tr -d ':'
142149

sed:

echo "14:21:49" | sed -e 's/://g'
142149

perl:

echo "14:21:49" | perl -lpe 's/://g'
142149

In comments you have scan_utc_time=$(scan_utc_time | sed 's/[^0-9]*//g') as what does not work.

That likely needs to be scan_utc_time=$(echo "$scan_utc_time" | sed 's/[^0-9]*//g')

ie, you are missing the sigil of $ to dereference the value. As habit, that should be quoted as well.

dawg
  • 98,345
  • 23
  • 131
  • 206
1

Plain shell parameter expansion:

scan_utc_output_time=${scan_utc_input_time//:/}
glenn jackman
  • 238,783
  • 38
  • 220
  • 352