Hi Folks,
I have a log that contains data as shown below:
11:59:43,144 [strategy.SNTH] (1,850) Signal : ....
11:59:44,109 [strategy.SNTH] (1850) Bps : .....
I wish to remove "[strategy.SNTH]" from all lines and it is on the start of every line. I have achieved that successfully using the command:
tail -f imp.log | sed 's/\ \[\<strategy.SNTH\>\]//g'
OR
tail -f imp.log | perl -pe "s/\ \[strategy\.SNTH\]//g"
I also wish to remove all lines containing the word "Bps". I achieved that using the following command:
tail -f imp.log |grep -v 'Bps'
The issue is, I cannot figure out how to string the two commands together.
Help please!
Regards,
Umair
---------- Post updated at 12:15 PM ---------- Previous update was at 12:14 PM ----------
And something to remove the milliseconds at the start of each line would be much appreciated too.
11:59:44,109 to just 11:59:44
Thanks.
Tytalus
2
one way:
tail -f imp.log | sed -n '/Bps/!s/\ \[\<strategy.SNTH\>\]//g;s/\([0-9][0-9]\),[^ ]*/\1/;p'
Thanks Tytalus but it doesn't entirely work. I'm getting the following results from your query:
11:59:43 (1,850) Signal : ....
11:59:44 [strategy.SNTH] (1850) Bps : .....
11:59:43 (1,850) Signal : ....
11:59:44 [strategy.SNTH] (1850) Bps : .....
11:59:43 (1,850) Signal : ....
11:59:44 [strategy.SNTH] (1850) Bps : .....
11:59:43 (1,850) Signal : ....
11:59:44 [strategy.SNTH] (1850) Bps : .....
11:59:43 (1,850) Signal : ....
11:59:44 [strategy.SNTH] (1850) Bps : .....
The millseconds are gone and for the correct signal lines [strategy.SNTH] is gone too but the Bps lines have not been filtered out.
tail -f imp.log | nawk '!/Bps/' | sed -e 's/\ \[\<strategy.SNTH\>\]//g' -e 's/\([0-9][0-9]\),[^ ]*/\1/g'
---------- Post updated at 02:47 PM ---------- Previous update was at 02:40 PM ----------
This is a slightly stronger match: -
tail -f imp.log | nawk '!/Bps/' | sed -e 's/\ \[\<strategy.SNTH\>\]//g' -e 's/\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\),[0-9][0-9]*/\1/g'
---------- Post updated at 02:59 PM ---------- Previous update was at 02:47 PM ----------
Your pattern for strategy.SNTH is a little overcomplicated: -
s/ \[strategy.SNTH\]//g
is sufficient