Skip to content

Commit cfb2534

Browse files
committed
Small updates of text chapter.
1 parent 923c6aa commit cfb2534

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

presentation/linux_bash_metacentrum_course.tex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,10 +2803,10 @@ \subsection{AWK}
28032803
\begin{frame}[fragile]{Get a~column with awk}
28042804
\begin{itemize}
28052805
\item AWK is scripting language mainly for text manipulations
2806-
\item Can not select column according to its name (Perl can do that)
2807-
\item Can do things other BASH tools can not (easily) do --- better manipulation with columns, calculations,~\ldots
2806+
\item Can do things other BASH tools can not (easily) do --- better manipulation with columns, calculations, work with multi-line patterns,~\ldots
28082807
\item Has complicated syntax, it is hard to read, it is not similar to other tools --- Perl can do more and is more common (learn it instead)\ldots
28092808
\item Supports regular expressions, slide \ref{regexp}
2809+
\item Can not select column according to its name (Perl can do that)
28102810
\item For more information see manuals \url{https://www.gnu.org/software/gawk/manual/}, \url{https://en.wikibooks.org/wiki/An_Awk_Primer} and \url{https://www.grymoire.com/Unix/Awk.html}
28112811
\end{itemize}
28122812
\vfill
@@ -2881,7 +2881,7 @@ \subsection{Manipulations}
28812881
LC_ALL=C sort ... # To force use of English locale use
28822882
# Take into account only spaces and alphanumerical characters (ignore
28832883
# any other)
2884-
sort -d textfile
2884+
sort -d textfile # Only spaces and alphanumerical characters
28852885
sort -r textfile # Reverse order
28862886
sort -f textfile # Ignore character case (not case sensitive)
28872887
sort -m textfile1 textfile2 # Merge already sorted text files
@@ -2960,7 +2960,7 @@ \subsection{Manipulations}
29602960
# Search and replace ("s") all occurrences ("g") of "find" by "replace"
29612961
sed 's/find/replace/g' textfile
29622962
# Replace third occurrence of pattern on every line
2963-
sed 's/pattern/Replace/3' # 's/.../.../' replace only third occurrence
2963+
sed 's/pattern/Replace/3' # 's/.../.../3' replace only third occurrence
29642964
sed '1,7s/...' # To work only on particular line, place single number or
29652965
sed '5s/...' # range (e.g. 1,7) right before "s" ("$" for last line)
29662966
sed '1~2n;s/F/R/g' # Work on every second line, starting by line 1
@@ -2991,7 +2991,7 @@ \subsection{Manipulations}
29912991
# Replace size column (2nd numeric) by "size:TAB<file size>b"
29922992
# Second sed replaces any white spaces by single TAB
29932993
ls -l | sed 's/\([0-9]\+\)/size:\t\1b/2' | sed 's/[[:blank:]]\+/\t/g'
2994-
head long_text.txt | sed '/^$/d' # Delete blank (empty) lines
2994+
sed '/^$/d' long_text.txt | less # Delete blank (empty) lines
29952995
head long_text.txt | sed '6d' # Delete 6th line
29962996
\end{bashcode}
29972997
\end{frame}
@@ -3027,11 +3027,11 @@ \subsection{Manipulations}
30273027
ls -l | sed 's/[0-9]\{4,\}/BIG!/' # Replace 4 or more digits by "BIG!"
30283028
sed -E ... ; sed -r ... # Use extended regular expressions (see further)
30293029
# Remove blank space (spaces or tabs) on beginning of each line
3030-
sed 's/^[[:blank:]]\+//'
3030+
sed 's/^[[:blank:]]\+//' textfile
30313031
# Remove suffix from names of *.sh files - compare variants
30323032
ls -1 *.sh | sed 's/\.sh$//' # Note '$' to ensure end of line
30333033
ls -1 *.sh
3034-
find . -name "*.sh" | sed 's/^\.\///;s/\.sh//' # Note chaining patterns
3034+
find . -name "*.sh" | sed 's/^\.\///;s/\.sh//' # Note chaining of patterns
30353035
find . -name "*.sh" # It searches also in subdirectories
30363036
\end{bashcode}
30373037
\begin{itemize}
@@ -3041,8 +3041,8 @@ \subsection{Manipulations}
30413041
30423042
\begin{frame}[fragile]{Joining}
30433043
\begin{itemize}
3044-
\item Generally, most of tools work per-line, \texttt{paste} appends columns (slide~\ref{cutpaste})
3045-
\item Join compares every matching lines (by default 1$^{st}$ field) and creates all combinations --- ensure to have sorted input files with unique text
3044+
\item Generally, most of tools work per-line, \texttt{paste} appends columns (see also slide~\ref{cutpaste})
3045+
\item \texttt{join} compares every matching lines (by default 1$^{st}$ field) and creates all combinations --- ensure to have sorted input files with unique text
30463046
\begin{itemize}
30473047
\item E.g. if 1$^{st}$ file contains \texttt{A~B} and \texttt{A~C} and 2$^{nd}$ file \texttt{A~D} and \texttt{A~E}, the result will be \texttt{A~B D}, \texttt{A~B E}, \texttt{A~C D} and \texttt{A~C E}
30483048
\end{itemize}
@@ -3241,7 +3241,7 @@ \subsection{Editors}
32413241
\begin{itemize}
32423242
\item \texttt{i} or \texttt{Insert} key to enter \textit{insert mode}, \texttt{:} to enter \textit{command mode}
32433243
\end{itemize}
3244-
\item \textbf{Insert} --- in bottom left corner \enquote{{-}- \texttt{INSERT} -{-}} is displayed, the most familiar mode, normal typing etc., exit to normal mode by \texttt{ESC} key
3244+
\item \textbf{Insert} --- in bottom left corner \enquote{\texttt{{-}- INSERT -{-}}} is displayed, the most familiar mode, normal typing etc., exit to normal mode by \texttt{ESC} key
32453245
\item \textbf{Command} --- in bottom left corner \texttt{:} is displayed, awaits commands, exit to normal mode by \texttt{Backspace} key (delete \enquote{\texttt{:}})
32463246
\end{enumerate}
32473247
\begin{itemize}
@@ -3291,8 +3291,9 @@ \subsection{Regular expressions}
32913291
\item Manipulate the text --- flip, reformat, replace,~\ldots
32923292
\item Syntax is variable among programming languages and applications
32933293
\item There are commonly more solutions for one task
3294-
\item Well supported in \texttt{grep}, \texttt{sed}, \texttt{vim}, \texttt{emacs},~\ldots
3294+
\item Well supported in \texttt{grep}, \texttt{sed}, \texttt{awk}, \texttt{vim}, \texttt{emacs},~\ldots
32953295
\item Probably the most advanced is \href{https://www.perl.org/}{Perl}
3296+
\item Implementations can differ among tools
32963297
\end{itemize}
32973298
\vfill
32983299
\url{https://xkcd.com/208/}

0 commit comments

Comments
 (0)