Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Picasoft
APIs
Init
Linux
Commits
795858a1
Verified
Commit
795858a1
authored
Jan 21, 2019
by
Stephane Bonnet
Browse files
traitement de fichiers
parent
329bf68c
Pipeline
#33802
failed with stage
in 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/cli/semi-adv.tex
View file @
795858a1
...
...
@@ -605,15 +605,152 @@ BuildID[sha1]=b636f50d85c3cca7cf2518030446660c1d90d660, stripped
\cmd
{
file
}
fonctionne en analysant réellement le contenu du fichier, il ne se sert pas de
l'extension.
\end{block}
\end{frame}
\subsection
{
Manipuler des fichiers
}
\begin{frame}
[fragile]
{
Un peu de manipulation de fichiers
}
%% cut
%% sort
%% wc
Il existe de nombreuses commandes de manipulation de fichiers utiles:
\begin{description}
\item
[\cmd{wc}]
Compte les lignes, mots, etc. d'un fichier
\item
[\cmd{sort}]
Trie les lignes d'un fichier
\item
[\cmd{uniq}]
Supprime les doublons adjacents d'un fichier
\item
[\cmd{tr}]
Transforme les caractères d'un fichier
\item
[\cmd{diff}]
Compare deux fichiers et affiche les différences
\item
[\cmd{cut}]
Découpe un fichier en champs
\item
[\cmd{sed}]
Édite un fichier à la volée
\end{description}
\end{frame}
\begin{frame}
[fragile]
{
\cmd
{
tr
}}
\begin{block}
{}
\begin{description}
\item
[\cmd{tr}]
Transforme des caractères entre deux ensembles
\end{description}
\end{block}
\begin{beamercolorbox}
[rounded=true,shadow=true]
{
terminal
}
\begin{Verbatim}
$
cd ~
/
api ; echo 'The quick brown fox jumps over the lazy dog' > file.txt
\end
{
Verbatim
}
\end
{
beamercolorbox
}
\begin
{
columns
}
\begin
{
column
}{
.
45
\textwidth
}
Un peu de cryptographie...
\begin
{
beamercolorbox
}
[
rounded
=
true,shadow
=
true
]
{
terminal
}
\begin
{
Verbatim
}
$
\textcolor
{
yellow
}{
tr 'a-z' 'b-za' < file.txt
}
Tif rvjdl cspxo gpy kvnqt pwfs uif mbaz eph
\end{Verbatim}
\end{beamercolorbox}
Passage en capitales...
\begin{beamercolorbox}
[rounded=true,shadow=true]
{
terminal
}
\begin{Verbatim}
$
\textcolor
{
yellow
}{
tr
[
:lower:
]
[
:upper:
]
< file.txt
}
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
\end
{
Verbatim
}
\end
{
beamercolorbox
}
\end
{
column
}
\begin
{
column
}{
.
45
\textwidth
}
Séparons les mots...
\begin
{
beamercolorbox
}
[
rounded
=
true,shadow
=
true
]
{
terminal
}
\begin
{
Verbatim
}
$
\textcolor
{
yellow
}{
tr [:blank:] '
\textbackslash
{}
n' < file.txt
}
The
quick
brown
fox
jumps
over
the
lazy
dog
\end{Verbatim}
\end{beamercolorbox}
\end{column}
\end{columns}
\begin{alertblock}
{
Séquences d'échappement
}
Interprétées par le shell comme des caractères spéciaux:
\cmd
{
\textbackslash
{}
n
}
est un retour à la ligne,
\cmd
{
\textbackslash
{}
t
}
une
tabulation...
\end{alertblock}
\end{frame}
\begin{frame}
[fragile]
{
\cmd
{
cut
}}
\begin{block}
{}
\begin{description}
\item
[\cmd{cut}]
Supprime des sections de chaque ligne d'un fichier.
\end{description}
\end{block}
\begin{columns}
\begin{column}
{
.45
\textwidth
}
On garde les caractères 5 à 9...
\begin{beamercolorbox}
[rounded=true,shadow=true]
{
terminal
}
\begin{Verbatim}
$
\textcolor
{
yellow
}{
cut
-
c
5
-
9
file.txt
}
quick
\end
{
Verbatim
}
\end
{
beamercolorbox
}
\end
{
column
}
\begin
{
column
}{
.
45
\textwidth
}
On garde les champs
3
et
5
...
\begin
{
beamercolorbox
}
[
rounded
=
true,shadow
=
true
]
{
terminal
}
\begin
{
Verbatim
}
$
\textcolor
{
yellow
}{
cut -f 3,5 -d' ' file.txt
}
brown jumps
\end{Verbatim}
\end{beamercolorbox}
\end{column}
\end{columns}
\begin{alertblock}
{
Délimiteur
}
Le délimiteur de champs est par défaut la tabulation. L'option
\cmd
{
-d
}
permet de le changer.
\end{alertblock}
\end{frame}
\begin{frame}
[fragile]
{
\cmd
{
sed
}}
\begin{block}
{}
\begin{description}
\item
[\cmd{sed}]
(
\emph
{
Stream EDitor
}
) Édite le fichier ligne par ligne à la volée.
\end{description}
\end{block}
Remplaçons
\emph
{
brown
}
par
\emph
{
yellow
}
...
\begin{beamercolorbox}
[rounded=true,shadow=true]
{
terminal
}
\begin{Verbatim}
$
\textcolor
{
yellow
}{
sed 's
/
brown
/
yellow
/
g' file.txt
}
The quick yellow fox jumps over the lazy dog
\end
{
Verbatim
}
\end
{
beamercolorbox
}
\begin
{
itemize
}
\item
\cmd
{
s
}
est la commande de remplacement. Elle prend deux paramètres:
\begin
{
itemize
}
\item
le motif à rechercher
(
c'est une regex
)
\item
le texte à substituer aux correspondances
\end
{
itemize
}
\item
\cmd
{
g
}
indique que le remplacement affecte toutes les occurrences.
\item
Le séparateur est le caractère qui suit directement la commande
\cmd
{
s
}
.
On aurait pu utiliser un autre caractère que ``
/
''.
\end
{
itemize
}
\begin
{
alertblock
}{
RTFM
}
\cmd
{
sed
}
est une commande très puissante mais très complexe. Lisez le man.
\end
{
alertblock
}
\end
{
frame
}
\subsection
{
Combiner les commandes: les pipes
}
...
...
@@ -631,9 +768,6 @@ BuildID[sha1]=b636f50d85c3cca7cf2518030446660c1d90d660, stripped
\begin
{
frame
}
[
fragile
]
{
Mettre fin à des processus
}
\end
{
frame
}
\begin{frame}
[fragile]
{
Terminaux
}
\end{frame}
\begin
{
frame
}
[
fragile
]
{
Exécution en arrière plan
}
\end
{
frame
}
...
...
@@ -652,5 +786,4 @@ BuildID[sha1]=b636f50d85c3cca7cf2518030446660c1d90d660, stripped
\end
{
frame
}
\begin
{
frame
}
[
fragile
]
{
Rechercher dans l'historique
}
\end{frame}
\end
{
frame
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment