1

Is there any way to grep some text from large file and mark that in BOLD letters in Linux BASH shell ? Like

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 15G 11G 3.3G 76% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
/dev/sda3 51G 45G 3.8G 93% /home
/dev/sdc1 917G 359G 512G 42% /data

I have above output and I want whenever system mails me about this df output the /data line should be in bold letters.

Volker Siegel
  • 3,277
  • 2
  • 24
  • 35
Yogesh
  • 663
  • 8
  • 17
  • Do you want to see the complete text with the matched text highlighted? Please provide more details about your requirements. with GNU grep: `grep --color=auto` – glenn jackman Oct 16 '13 at 11:51
  • `any way to grep some text from large file` -- yes. `mark that in BOLD letters in Linux BASH shell` -- would depend upon your *terminal*. – devnull Oct 16 '13 at 11:51

2 Answers2

3

Using ANSI escape sequence you can do this (though this is terminal dependent):

echo -e "\033[1m$(grep '/data' file)\033[0m"

Will produce:

/dev/sdc1 917G 359G 512G 42% /data

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks, it worked, but i have some extended requirement in this regard,I want a whole line in BOLD if pattern is found. – Yogesh Oct 16 '13 at 12:17
0

Bash doesn't really have bold (it does have bright which is effectively equivilent). You could use sed to insert the bash control codes, but if you are less concerned with the exact colour choice, you can use

grep --color -E "text match pattern|" mylargefile

To get grep to do the highlighting. (see Colorized grep -- viewing the entire file with highlighted matches for alternatives and discussion)

Community
  • 1
  • 1
Oliver Matthews
  • 7,497
  • 3
  • 33
  • 36