Paul Paul - 6 months ago 29
Linux Question

Remove colon between values in array bash

up vote
0
down vote

I have file:

name name1 name2 name3 name4 name[n]
value1 A:A B:B C:C D:D E:E
value2 A:A B:B C:C D:D E:E
value[n] A:A B:B C:C D:D E:E


And I need an output

name name1 name2 name3 name4 name[n]
value1 AA BB CC DD EE
value2 AA BB CC DD EE
value[n] AA BB CC DD EE


Just simply remove colon between values. I would try something like:

awk '{split($2,arr1,/:/); print arr1[1]arr1[2]}' file


wich gives me just column $2. I do not need awk solution.

Thank you for any help.

Answer

Question was to only remove character colon (:), thus avoiding complexity not requested for me leads to:

cat file_with_colons | tr -d ':'

or as @andlrc pointed out in comment of course (if no other process/pipe wanted):

tr -d ':' < file_with_colons

From man page on my system:

TR(1)                     BSD General Commands Manual                        TR(1)

NAME
     tr -- translate characters

SYNOPSIS
     tr [-Ccsu] string1 string2
     tr [-Ccu] -d string1
     tr [-Ccu] -s string1
     tr [-Ccu] -ds string1 string2

DESCRIPTION
     The tr utility copies the standard input to the standard output with substitution or deletion of selected characters.

     The following options are available:

# ... 8< - -   
     -d      Delete characters in string1 from the input.
# - - >8 ...
Comments