Skip to content

Commit d05abd4

Browse files
committed
Small updates of text chapter.
1 parent 54a1af3 commit d05abd4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

presentation/linux_bash_metacentrum_course.tex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ \subsection{Network}
21982198
\end{itemize}
21992199
\end{frame}
22002200
2201-
\begin{frame}[fragile]{Basic network information and testing} % TODO rewrite netstat examples for ss
2201+
\begin{frame}[fragile]{Basic network information and testing} % TODO Rewrite netstat examples for ss
22022202
\begin{bashcode}
22032203
hostname # Get name of the computer
22042204
ping web.natur.cuni.cz # Ping host. Is it alive? Cancel by Ctrl+C
@@ -2615,7 +2615,7 @@ \section{Text}
26152615
unix2mac textfile # Convert text file from UNIX to old Mac EOL
26162616
dos2unix textfile # Convert text file from Windows to UNIX EOL
26172617
mac2unix textfile # Convert text file from old Mac to UNIX EOL
2618-
enca -h # See usage
2618+
enca -h # See usage - enca converts various encodings (similar to iconv)
26192619
enca file.txt # Detects encoding of file.txt
26202620
enca -x utf8 file.txt # Convert file.txt into UTF-8
26212621
# Converts encoding of input file (ISO-8859-2) to outfile in UTF-8
@@ -2633,7 +2633,7 @@ \subsection{Reading}
26332633
\begin{frame}[fragile]{Read text file}
26342634
\begin{bashcode}
26352635
cat # Read or join (using redirects) files; 'cat --help' for options
2636-
cat long_text.txt # Print content of text file
2636+
cat long_text.txt # Print content of text file to the screen (stdout)
26372637
cat textfile1 >> textfile2 # Append textfile1 to the end of textfile2
26382638
nl long_text.txt # Like 'cat -n', prints textfile with line numbers
26392639
tac textfile # Like cat, but prints lines in reverse order
@@ -2679,17 +2679,19 @@ \subsection{Extractions}
26792679
\begin{bashcode}
26802680
grep --help # See plenty of options
26812681
grep -parameters pattern textfile # Write lines containing pattern
2682-
grep user /etc/passwd # Write all lines in passwd containing user
2683-
cat /etc/passwd | grep user # Same as above
2684-
grep -v user /etc/passwd # Write all lines in passwd NOT containing user
2685-
grep -c user /etc/passwd # Get number of lines in passwd containing user
2682+
grep user /etc/passwd # Write all lines in passwd file containing "user"
2683+
cat /etc/passwd | grep user # Same as above, common, but superfluous style
2684+
grep -v user /etc/passwd # Write all lines in passwd NOT containing "user"
2685+
grep -c user /etc/passwd # Get number of lines in passwd containing "user"
26862686
grep -i USER /etc/passwd # -i for case insensitive
26872687
grep -q ... # quiet - no output (only T/F) - good for testing in scripts
26882688
grep -ls user /etc/* # -l print files with pattern, -s suppress errors
2689-
grep "longer text" textfile # Extract whole phrase
2689+
grep "longer text" textfile # Extract whole phrase (must be quoted)
26902690
\end{bashcode}
26912691
\begin{itemize}
26922692
\item Grep supports regular expressions, slide \ref{regexp}
2693+
\item Grep works per-line, multiline patterns are more or less impossible (use AWK or Perl instead) --- this is general limitation of basic tools
2694+
\item Grep (and sed and other tools) in macOS is outdated, missing plenty of functions --- use version from Homebrew (slide~\ref{homebrew})
26932695
\end{itemize}
26942696
\end{frame}
26952697
@@ -2787,7 +2789,7 @@ \subsection{AWK}
27872789
grep home /etc/passwd | awk -F ':' '{print $5 ", username:", $1}'
27882790
# Separate columns by TAB, /^d/ for lines starting with "d" (only dirs)
27892791
ls -l | awk '/^d/ { print $8 "\t" $3 }'
2790-
# Print on even lines ">", former column 1, new line, former column 2
2792+
# Print on even lines ">", former column 1, new line, former column 2:
27912793
# 2 columns into 2 lines (create FASTA from tabular record)
27922794
awk '{print ">"$1"\n"$2}' awk_test_file.tab | less -S
27932795
# Print field 1, TAB (\t), length of field 2, TAB and field 2
@@ -2815,7 +2817,7 @@ \subsection{AWK}
28152817
\end{bashcode}
28162818
\end{frame}
28172819
2818-
\begin{frame}[fragile]{AWK examples III}
2820+
\begin{frame}[fragile]{AWK examples III} % TODO Add more awk examples
28192821
\begin{bashcode}
28202822
# For every 4th line starting from line 2 of FASTQ file (from line 2
28212823
# every 4th line contains the DNA sequence) print its length (bzcat
@@ -2848,9 +2850,9 @@ \subsection{Manipulations}
28482850
bzcat Oxalis_hirta_R1.fastq.bz2 | awk 'NR%4==2{print $0}' | sort -u
28492851
sort -b textfile # Ignore leading blanks (space on beginning of line)
28502852
sort -k 2 -n cut_awk_test_file.tsv # Sort according to 2nd field
2851-
# Filters following identical lines - only unique are printed (to get
2852-
# unique lines from whole file, sort it)
2853+
# Filters following identical lines - only unique are printed
28532854
uniq textfile
2855+
sort textfile | uniq # To get unique lines from whole file, sort it first
28542856
\end{bashcode}
28552857
\end{frame}
28562858

0 commit comments

Comments
 (0)