Document ClassesListings package: Bash - colour text

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
Drake
Posts: 6
Joined: Sun Mar 30, 2008 2:31 pm

Listings package: Bash - colour text

Post by Drake »

Hi everybody.
I´m looking for any help with little problem with listings package. I tried find some example on google, but no luck.

I have some bash output (response) and I need put them to my project. For this purpose I´m using the listings package (it´s great).
(I´m using listings, color package)

There is a part of my response:

Code: Select all

[00:00:00] 80 keys tested (256.41 k/s)
                           
                          KEY FOUND! [ 12345678 ]
                          
      Master Key     : 37 3E FB 3B F8 6E 40 41 69 07 16 26 FE 89 81 AD
                       F4 CF 55 95 93 51 CB ED 50 35 0A A2 04 ED C9 29
      
      Transcient Key : 79 A4 3D 2B 5F 00 99 3D 83 BD 11 4B FE C1 D9 83
And now I need some help - How can I do in simple way (if there is one) coloured few part of this response? I read the manual for listings package, but I´m not understand it (How should I use: keywords, otherkeywords, morekeywords, alsodigit, alsoother, ...)

My code for LaTeX is:

Code: Select all

\lstset{backgroundcolor=\color{bezovaC}, basicstyle=\scriptsize, language=bash,
	moredelim=[is][\bfseries]{|}{|},
	%
	classoffset=0,
        keywords=[1]{KEY, FOUND}, keywordstyle=[1]\color{red}\bfseries,
	classoffset=1,
	otherkeywords={!},
	classoffset=0
	} 
%			
\begin{lstlisting}[frame=single, framerule=1pt]	
                                  Aircrack-ng 0.9.1 r687

                   [00:00:00] 80 keys tested (256.41 k/s)
                           
                          KEY FOUND! [ 12345678 ]
                          
      Master Key     : 37 3E FB 3B F8 6E 40 41 69 07 16 26 FE 89 81 AD
                       F4 CF 55 95 93 51 CB ED 50 35 0A A2 04 ED C9 29
      
      Transcient Key : 79 A4 3D 2B 5F 00 99 3D 83 BD 11 4B FE C1 D9 83
\end{lstlisting}
%
With this code I was able to make "KEY FOUND!" in red color only. But I need more color highlight:
"12345678" in blue
"Master Key" in green
"37 3E FB 3B F8 6E 40 41 69 07..." in other color and so on...

Anybody known the way how can I do that? :-( Maybe one of you already do something like this and maybe can share with the source code.
Is there something like tags <...> and by the definitions everything inside is coloured?

Any idea? Thank to everybody for any help.
(Sorry to my english grammar, I hope that it is understandable :o) )

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Drake
Posts: 6
Joined: Sun Mar 30, 2008 2:31 pm

Listings package: Bash - colour text

Post by Drake »

Solved!
I had to read more carefully manual of listings package. Sorry for spam :mrgreen:
But maybe for someone who not read carefully like me...

Code: Select all

moredelim=[is][\color{Bittersweet}]{+}{+}, %
moredelim=*[is][\color{blue}\bfseries]{&}{&}, % 
moredelim=**[is][\color{Plum}]{@}{@}, %
moredelim=***[is][\color{RoyalBlue}]{*}{*}, % 
moredelim=***[is][\color{OliveGreen}]{'}{'}, % 
Paste to body of "\lstset{...}"

Code: Select all

%
\begin{lstlisting}[frame=single, framerule=1pt]
|Transcient Key| : +79 A4 3D 2B 5F 00 99 3D 83 BD 11 4B FE C1 D9 83+
\end{lstlisting}
%
All between delimeters +...+ will be coloured with specific color.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Listings package: Bash - colour text

Post by localghost »

It is most helpful if you provide your solution in form of a minimal working example (MWE).


Best regards and welcome to the board
Thorsten
Post Reply