shaveax
shaveax

Reputation: 478

How to delete specific patterns with sed bash

i have a bash script that contains the following :

#!/bin/bash
##############################################################
# LOCAL COLORS                                               #
##############################################################
export nc="\e[0m"
export underline="\e[4m"
export bold="\e[1m"
export green="\e[1;32m"
export red="\e[1;31m"
export yellow="\e[1;33m"
export blue="\e[1;34m"
export cyan="\e[1;36m"

and when i open the log:

$ echo "${red}############${nc}" | tee log

the characters from the variables appears, so i've trying to delete it using sed like this:

sed -i 's|\e[1;31m||g' log

but always i have the following error :

sed: -e expression #1, char 10: unterminated `s' command

i will appreciate your help with this Thanks

Upvotes: 1

Views: 68

Answers (2)

Cyrus
Cyrus

Reputation: 88553

I suggest to use:

sed -i 's|\x1b\[1;31m||g' log

Upvotes: 1

l'L'l
l'L'l

Reputation: 47159

In sed you'll likely need to escape the \e and the [:

sed -i 's|\\e\[1;31m||g'

Otherwise they get misinterpreted and will break the pattern.

Upvotes: 1

Related Questions