Replacing multiple bars (special char) with a tab using sed
4 answers
you need to avoid +
$ sed 's/|\+/\t/g' file
BRADI5G20430 BRADI5G20430.1 1
or you can use the -r
sed option , but this time it +
will be "one or more" and you need to escape the "|" as in regex it means alternation.
$ sed -r 's/\|+/\t/g' file
BRADI5G20430 BRADI5G20430.1 1
or use awk, set the field separator to "|" and then set the output field separator OFS
to the tab\t
eg,
$ awk -F"|" '{$1=$1}1' OFS="\t" file
BRADI5G20430 BRADI5G20430.1 1
this replaces every tab "|". If you want to replace all "|" with one tab
$ awk '{gsub(/\|+/,"\t")}1' file
BRADI5G20430 BRADI5G20430.1 1
+3
source to share