LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-12-2012, 06:53 AM   #1
prentmee
LQ Newbie
 
Registered: May 2007
Location: Wrightstown WI
Distribution: Red Hat / AIX
Posts: 6

Rep: Reputation: 1
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.
 
Old 12-12-2012, 06:57 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 844
Blog Entries: 2

Rep: Reputation: 212Reputation: 212Reputation: 212
Code:
sed '/Total number of bytes transferred/s/.*/\e[1m&\e[0m/'  temp1_log
 
Old 12-12-2012, 08:16 AM   #3
prentmee
LQ Newbie
 
Registered: May 2007
Location: Wrightstown WI
Distribution: Red Hat / AIX
Posts: 6

Original Poster
Rep: Reputation: 1
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.
 
Old 12-12-2012, 08:50 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
linosaurusroot's solution is missing a $, try this:
Code:
sed $'/Total number of bytes transferred/s/.*/\e[1m&\e[0m/'  temp1_log
 
Old 12-12-2012, 10:08 AM   #5
prentmee
LQ Newbie
 
Registered: May 2007
Location: Wrightstown WI
Distribution: Red Hat / AIX
Posts: 6

Original Poster
Rep: Reputation: 1
worked thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash coloring output Jerry Mcguire Programming 1 08-11-2011 02:44 AM
Perl script to replace a line after finding a previous line Mark1986 Programming 1 02-28-2011 06:09 PM
[SOLVED] Finding bugs in bash scripts, Analyis tool for bash traene Programming 2 10-31-2009 12:42 PM
Finding the last command line argument (bash) pete1234 Programming 20 10-30-2006 11:20 AM
bash ls not coloring files, directories etc mr_smith Red Hat 2 08-30-2006 08:05 AM


All times are GMT -5. The time now is 05:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration