Friday, June 22, 2018

Using translate "tr" to remove space or replace chars

Using translate (tr) to squeeze space :
# cat test
 Intel(R) Core(TM)   iii7-6600U CPU @      2.60GHz
 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
#

squeeze repeated spaces to a single space:
# cat test |tr -s ' '
 Intel(R) Core(TM) iii7-6600U CPU @ 2.60GHz
 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
#

Squeeze repeated 'i' to a single 'i' :
# cat test |tr -s 'i'
 Intel(R) Core(TM)   i7-6600U CPU @      2.60GHz
 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
#

squeeze all 'i' and replace to 'X' :
# cat test |tr -s 'i' 'X'
 Intel(R) Core(TM)   X7-6600U CPU @      2.60GHz
 Intel(R) Core(TM) X7-6600U CPU @ 2.60GHz
#

No comments:

Post a Comment