LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   BASH - finding and coloring a whole line (http://www.linuxquestions.org/questions/linux-general-1/bash-finding-and-coloring-a-whole-line-4175441111/)

prentmee 12-12-2012 06:53 AM

BASH - finding and coloring a whole line
 
I'm writing a shell script to check my nightly backup logs. I want to find a line and high light the line. the sed command works but I want it to include the variable text on both sides of the found text.

cat temp1_log | sed $'s/Total number of bytes transferred/\e[1m&\e[0m/'

output example:
12/10/12 21:28:03 Total number of objects expired: 30
12/10/12 21:28:03 Total number of objects failed: 0
12/10/12 21:28:03 Total number of bytes inspected: 29.23 GB
12/10/12 21:28:03 Total number of bytes transferred: 17.63 GB
12/10/12 21:28:03 Data transfer time: 680.32 sec
12/10/12 21:28:03 Network data transfer rate: 27,181.52 KB/sec


as always any help would be greatly appreciated.

linosaurusroot 12-12-2012 06:57 AM

Code:

sed '/Total number of bytes transferred/s/.*/\e[1m&\e[0m/'  temp1_log

prentmee 12-12-2012 08:16 AM

that didn't work.

output is now:
sed '/Total number of bytes transferred/s/.*/\e[1m&\e[0m/' temp1_log

12/10/12 21:28:03 Total number of objects expired: 30
12/10/12 21:28:03 Total number of objects failed: 0
12/10/12 21:28:03 Total number of bytes inspected: 29.23 GB
e[1m12/10/12 21:28:03 Total number of bytes transferred: 17.63 GBe[0m
12/10/12 21:28:03 Data transfer time: 680.32 sec
12/10/12 21:28:03 Network data transfer rate: 27,181.52 KB/sec

and there is no high lighting.

druuna 12-12-2012 08:50 AM

linosaurusroot's solution is missing a $, try this:
Code:

sed $'/Total number of bytes transferred/s/.*/\e[1m&\e[0m/'  temp1_log

prentmee 12-12-2012 10:08 AM

worked thanks


All times are GMT -5. The time now is 02:20 AM.