LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2012, 12:56 PM   #1
manojb
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Rep: Reputation: Disabled
Lightbulb Redirected text to be with bold using shell script


I am redirecting some texts to a '.txt' file using shell. Is is possible by any means that, I can make it bold or apply some text color to some particular lines only ?

For example:

if my text files contains the following:

Header1
Content1
Sub Content1
FootNote1

Here line1 should be bold, line2, 3 and 4 should be in different text colors.

I want to do it using shell programming itself...
 
Old 10-29-2012, 01:19 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
By default, such options depend upon the OS and shell you're using. What is your OS?
Read about formatting text in shell script: http://www.java-samples.com/showtuto...utorialid=1383
But I think that such formatting may cause little latency while executing the script, because of such formatting commands in it.
 
Old 10-29-2012, 01:27 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by manojb View Post
...texts...'.txt'...it
You can specify text in shell scripts using printf and some bash trickery...

Code:
printf "\e[1;31mContent1\n\033[0m" && printf "\e[1;31mSub Content1\n\033[0m" && printf "\e[1;31mFootNote1\n\033[0m"
Values for various colors described here...
 
Old 10-29-2012, 01:28 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Text files don't permit formatting. Actually you can write down color escape sequences together with the text, but you have to use an application able to interpret them in order to see the colors, the bold text and so on. Example:
Code:
$ echo -e '\e[4;31mThis text is red underlined\e[0m' > file
Then if you use cat you should see the color:
Code:
$ cat file
This text is red underlined
The option -v of cat reveals the actual content of the file:
Code:
$ cat -v file
^[[4;31mThis text is red underlined^[[0m
You can find a list of color escape sequences in this ArchWiki page: https://wiki.archlinux.org/index.php...rompt_and_Bash.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 06:00 AM
LXer: Simple PHP Diff Script - Shows Line Changes in Bold Text LXer Syndicated Linux News 0 05-28-2012 01:01 AM
how to print part of text of a text file in bold and color using shellscript swapna sree Linux - Newbie 25 07-12-2011 11:19 AM
Cannot read text from text file and store it in a variable using shell script anurupr Linux - Newbie 2 03-03-2010 01:38 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration