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.
EDIT:
I should mention, I’m reading a file as such:
while read line do
Then I want to perform any actions on line
for every line in the file.
Answer
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};'