Remove patterns from string using bash Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Remove patterns from string using bash without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to remove some patterns from a file input string (parsing file line by line). Here is a sample string:

1: (10/17 12:49:31.175) - CONSTANT ID1 - CONSTANT ID2: RAW DATA OUT     > [0x00,0xa2,…,0x00] 

And I want the output to be something like the following:

(12:49:31.175): RAW DATA OUT : [0x00,0xa2,…,0x00]

I have been trying to use egrep or sed but no luck so far, just keep getting errors or some “unterminated substitute pattern” error. Here is and example of what I have tried:

echo $line | sed -e 's/.*s([0-9]*:[0-9]*:[0-9]*.[0-9]*)'

Any help would be appreciated. I’m usually more of a batch file guy instead of bash on my Mac OS/X.


I should mention, I’m reading a file as such:

while read line

Then I want to perform any actions on line for every line in the file.


You can also call perl from bash. The -n arg makes it loop for each line. -e means the script is one line.

cat in.txt | perl -ne 's{.*(.*().*? (.*) -.*(:.*?)ss+.*([.*)}{$1$2$3 : $4};'
We are here to answer your question about Remove patterns from string using bash - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji