\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{TME520 (TME520)} \pdfinfo{ /Title (grep.pdf) /Creator (Cheatography) /Author (TME520 (TME520)) /Subject (grep Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{37A3A3} \definecolor{LightBackground}{HTML}{F2F9F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{grep Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{TME520 (TME520)} via \textcolor{DarkBackground}{\uline{cheatography.com/20978/cs/3986/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}TME520 (TME520) \\ \uline{cheatography.com/tme520} \\ \uline{\seqsplit{tme520}.com} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 26th April, 2015.\\ Updated 11th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Usage}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Grep sur la sortie standard}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}grep {[}{\emph{-options}}{]} {\emph{'chaîne'}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Grep sur un fichier}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}grep {[}{\emph{-options}}{]} {\emph{'chaîne'}} {\emph{nom\_de\_fichier}}} \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.9167 cm} x{2.8679 cm} x{7.0854 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{General Regular Expression Processor}} \tn % Row 0 \SetRowColor{LightBackground} \{\{bb\}\}{\bf{Opération}} & \{\{bb\}\}{\bf{Option}} & \{\{bb\}\}{\bf{Exemple}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Chercher une chaîne dans un ou plusieurs fichier(s)}} & & grep 'chaîne' \seqsplit{nom\_de\_fichier1} \seqsplit{nom\_de\_fichier2} ... nom\_de\_fichier{\emph{n}} \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} {\bf{Rechercher sans tenir compte de la casse}} & i & grep -i 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} {\bf{Utiliser des expressions régulières}} & & grep 'regexp' \seqsplit{nom\_de\_fichier} \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Chercher des mots complets}} & w & grep -w 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} {\bf{Afficher les {\emph{n}} lignes suivant la correspondance}} & A & grep -A n 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 21 (+ 4) % Row 6 \SetRowColor{LightBackground} {\bf{Afficher les {\emph{n}} lignes précédant la correspondance}} & B & grep -B n 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 25 (+ 4) % Row 7 \SetRowColor{white} {\bf{Afficher les {\emph{n}} lignes englobant la correspondance}} & C & grep -C n 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 29 (+ 4) % Row 8 \SetRowColor{LightBackground} {\bf{Rendre les résultats plus lisibles avec GREP\_OPTIONS}} & & export GREP\_OPTIONS='-{}-color=auto' \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.9167 cm} x{2.8679 cm} x{7.0854 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{General Regular Expression Processor (cont)}} \tn % Row 9 \SetRowColor{LightBackground} {\bf{Faire un grep récursif}} & r & grep -r \seqsplit{'vilain-pirate.cn'} \seqsplit{/var/log/apache2/archives/} \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} {\bf{Correspondances inversées : exclure ce dont on ne veut pas}} & v & grep -v 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 8 (+ 4) % Row 11 \SetRowColor{LightBackground} {\bf{Greper plusieurs chaînes}} & e & grep -e "pattern" -e "pattern" \seqsplit{nom\_de\_fichier} \tn % Row Count 11 (+ 3) % Row 12 \SetRowColor{white} {\bf{Compter le nombre de résultats}} & c & grep -c 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 14 (+ 3) % Row 13 \SetRowColor{LightBackground} {\bf{Afficher les noms des fichiers contenant la chaîne recherchée}} & l & grep -l 'chaîne' /var/log/* \tn % Row Count 19 (+ 5) % Row 14 \SetRowColor{white} {\bf{Ne montrer que l'exacte portion de chaîne correspondante}} & o & grep -o 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 23 (+ 4) % Row 15 \SetRowColor{LightBackground} {\bf{Afficher les numéros des lignes}} & n & grep -n 'chaîne' \seqsplit{nom\_de\_fichier} \tn % Row Count 26 (+ 3) % Row 16 \SetRowColor{white} {\bf{Identifier "Marcel" et "Roger" sans tenir compte de la casse}} & E et i et w & grep -E -i -w 'roger|marcel' /etc/passwd \tn % Row Count 30 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{Notez que {\emph{nom\_de\_fichier}} est optionnel. Sans lui, c'est la sortie standard qui est traitée.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5264 cm} x{11.7436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Expressions régulières : les jokers}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{.}} & N'importe quel caractère. \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{?}} & L'élément précédent est optionnel et apparaît maximum une fois. \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{*}} & L'élément précédent apparaît 0 fois ou plus. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \{\{bb\}\}{\bf{+}} & \{\{bb\}\}L'élément précédent apparaît 1 fois ou plus \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{\{n\}}} & L'élément précédent apparaît exactement {\emph{n}} fois. \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} {\bf{\{n,\}}} & L'élément précédent apparaît {\emph{n}} fois ou plus. \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{\{,m\}}} & L'élément précédent apparaît {\emph{m}} fois au maximum. \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} \{\{bb\}\}{\bf{\{n,m\}}} & \{\{bb\}\}L'élément précédent apparaît entre {\emph{n}} et {\emph{m}} fois. \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} {\bf{{[}:alnum:{]}}} & Caractères alphanumériques. \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} {\bf{{[}:alpha:{]}}} & Caractères alphabétiques. \tn % Row Count 24 (+ 2) % Row 10 \SetRowColor{LightBackground} {\bf{{[}:blank:{]}}} & Espace et tabulation. \tn % Row Count 26 (+ 2) % Row 11 \SetRowColor{white} {\bf{{[}:digit:{]}}} & Chiffres de 0 à 9. \tn % Row Count 28 (+ 2) % Row 12 \SetRowColor{LightBackground} {\bf{{[}:lower:{]}}} & Caractères alphabétiques en minuscules. \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5264 cm} x{11.7436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Expressions régulières : les jokers (cont)}} \tn % Row 13 \SetRowColor{LightBackground} {\bf{{[}:upper:{]}}} & Caractères alphabétiques en majuscules. \tn % Row Count 2 (+ 2) % Row 14 \SetRowColor{white} \{\{bb\}\}{\bf{{[}:space:{]}}} & \{\{bb\}\}Espace, tabulation, retour chariot, nouvelle ligne et tabulation verticale. \tn % Row Count 5 (+ 3) % Row 15 \SetRowColor{LightBackground} {\bf{{[}A-Za-z{]}}} & Caractères alphabétiques. \tn % Row Count 7 (+ 2) % Row 16 \SetRowColor{white} {\bf{{[}0-9{]}}} & Chiffres de 0 à 9. \tn % Row Count 8 (+ 1) % Row 17 \SetRowColor{LightBackground} {\bf{{[}0-9A-Za-z{]}}} & Caractères alphanumériques. \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.687 cm} x{6.5793 cm} x{8.6037 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Expressions régulières : ancrages et positions}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{\textasciicircum{}}} & Ligne commençant par. & grep '\textasciicircum{}Il était une fois' \seqsplit{/home/livres/lovestory}.txt \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{\$}} & Ligne terminant par. & grep 'divorcés.\$' \seqsplit{/home/livres/lovestory}.txt \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{\textasciicircum{}\$}} & Ligne vide. & \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} {\bf{\textbackslash{}\textless{}}} & Chaîne vide au début du mot. & grep '\textbackslash{}\textless{}pension\textbackslash{}\textgreater{}' \seqsplit{/home/livres/lovestory}.txt \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{\textbackslash{}\textgreater{}}} & Chaîne vide à la fin du mot. & \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} x{15.543 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Les caractères à échapper}} \tn % Row 0 \SetRowColor{LightBackground} \textbackslash{} & . \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {[} & \textasciicircum{} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \$ & ' \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} * & - (début de ligne uniquement) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Exemple : grep '192\textbackslash{}.168\textbackslash{}.1\textbackslash{}.254' /etc/hosts} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\$ et \textasciicircum{} ne sont pas à échapper s'ils sont utilisés comme marqueurs d'ancrage (début/fin de ligne).} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}