LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Redirected text to be with bold using shell script (https://www.linuxquestions.org/questions/linux-newbie-8/redirected-text-to-be-with-bold-using-shell-script-4175434643/)

manojb 10-29-2012 12:56 PM

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...

shivaa 10-29-2012 01:19 PM

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.

Habitual 10-29-2012 01:27 PM

Quote:

Originally Posted by manojb (Post 4817570)
...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...

colucix 10-29-2012 01:28 PM

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.


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