issue81:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
issue81:c_c [2014/05/13 13:50] – auntiee | issue81:c_c [2014/05/14 12:56] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 7: | Ligne 7: | ||
**Titre : Courriers des lecteurs - Sed** | **Titre : Courriers des lecteurs - Sed** | ||
- | **Le mois dernier, j'ai reçu un courriel de John, un lecteur de C & C. Il s' | + | **Le mois dernier, j'ai reçu un courriel de John, un lecteur de C & C. Il s' |
** | ** | ||
Ligne 55: | Ligne 55: | ||
• If you want the same formatting at the end, the RHS of the expression should almost always be the same, and if it isn't, it's an indicator that you're either going too complicated, | • If you want the same formatting at the end, the RHS of the expression should almost always be the same, and if it isn't, it's an indicator that you're either going too complicated, | ||
- | ** Quelques conseils sur la façon de faire pour chaque expression : Déterminez où vous devez insérer le caractère, car c'est cela qui définira où placer les groupes (dans notre cas, avant les espaces, donc le deuxième groupe commence presque toujours avant le caractère Espace) | + | ** Quelques conseils sur la façon de faire pour chaque expression : Déterminez où vous devez insérer le caractère, car c'est cela qui définira où placer les groupes (dans notre cas, avant les espaces, donc le deuxième groupe commence presque toujours avant le caractère Espace). |
- | • Travaillez par petits bouts. Commencez par une commande sed simple comme : sed -e " | + | • Travaillez par petits bouts. Commencez par une commande sed simple comme : sed -e " |
• Si vous avez des problèmes avec l' | • Si vous avez des problèmes avec l' | ||
- | • Si vous voulez le même formatage à la fin de la commande, le coté droit (RHS) de l' | + | • Si vous voulez le même formatage à la fin de la commande, le côté |
** | ** | ||
Ligne 90: | Ligne 90: | ||
# Check for any number of capital letters at the start of a line, followed by a space and more text, and insert a semicolon. | # Check for any number of capital letters at the start of a line, followed by a space and more text, and insert a semicolon. | ||
- | **# Recherchez chaque ligne commençant par une ou plusieurs lettres majuscules suivies d'une espace et encore du texte et insèrez | + | **# Recherchez chaque ligne commençant par une ou plusieurs lettres majuscules suivies d'une espace et encore du texte et insérez |
Ligne 99: | Ligne 99: | ||
**Les explications** | **Les explications** | ||
- | **La première expression dit à Sed « Cherche n' | + | **La première expression dit à Sed « Cherche n' |
The second expression tells Sed “Look for any 3 consecutive digits that are followed by a space and a letter or number, then insert a semi-colon”. What this matches is the date – the format of the date is always going to be so long that only one space is inserted between columns. Naturally, you could check for any number of spaces, but that could cause issues if you use numbers in your Projects. This will apply to any format of date where the year is at the end. This handles column 3 in our file. | The second expression tells Sed “Look for any 3 consecutive digits that are followed by a space and a letter or number, then insert a semi-colon”. What this matches is the date – the format of the date is always going to be so long that only one space is inserted between columns. Naturally, you could check for any number of spaces, but that could cause issues if you use numbers in your Projects. This will apply to any format of date where the year is at the end. This handles column 3 in our file. | ||
- | **La seconde expression dit à Sed « Recherche 3 chiffres consécutifs qui sont suivis par une espace et une lettre ou un chiffre, puis insère un point-virgule ». Cela correspond à la date la date - le format de la date sera toujours si long qu'une seule espace sépare la date de la colonne suivante. Bien sûr, on pourrait chercher un nombre quelconque d' | + | **La seconde expression dit à Sed « Recherche 3 chiffres consécutifs qui sont suivis par une espace et une lettre ou un chiffre, puis insère un point-virgule ». Cela correspond à la date - le format de la date sera toujours si long qu'une seule espace sépare la date de la colonne suivante. Bien sûr, on pourrait chercher un nombre quelconque d' |
The third expression can be translated as “Find all letters followed by a 1 or 2 digit number, followed by a slash, and insert the semi-colon.” The only column that contains a slash is our formatted date column – this applies therefore to the column before it (Project). The reason why I didn't include numbers in this case, is because the second expression could handle this if you tell Sed to accept any number of spaces after the 3 digits. This handles column 2 in our file. | The third expression can be translated as “Find all letters followed by a 1 or 2 digit number, followed by a slash, and insert the semi-colon.” The only column that contains a slash is our formatted date column – this applies therefore to the column before it (Project). The reason why I didn't include numbers in this case, is because the second expression could handle this if you tell Sed to accept any number of spaces after the 3 digits. This handles column 2 in our file. | ||
- | **La troisième expression peut être traduite comme « Recherche toutes lettres suivies par un nombre de 1 ou 2 chiffres, suivis d'un slash (ou barre oblique) et insère un point-virgule ». La seule colonne qui contient une barre oblique est notre colonne de date - cela s' | + | **La troisième expression peut être traduite comme « Recherche toutes lettres suivies par un nombre de 1 ou 2 chiffres, suivis d'un slash (ou barre oblique) et insère un point-virgule ». La seule colonne qui contient une barre oblique est notre colonne de date, cela s' |
The fourth expression handles the last line of the file, and inserting the 3 semi-colons before tasks. It essentially groups the entire line (10 tasks) and then inserts three semi-colons before that group. If you're adding semi-colons before any lines starting with numbers, then you should move this expression to the start of the list of expressions, | The fourth expression handles the last line of the file, and inserting the 3 semi-colons before tasks. It essentially groups the entire line (10 tasks) and then inserts three semi-colons before that group. If you're adding semi-colons before any lines starting with numbers, then you should move this expression to the start of the list of expressions, | ||
- | **La quatrième expression gère la dernière ligne du fichier et insére | + | **La quatrième expression gère la dernière ligne du fichier et insère |
** | ** | ||
The fifth expression simply states “Find the line that starts with any number of capital letters, and insert a space afterwards”. I go a little more specific, and state “followed by any number of spaces and more letters”. However, it's not necessary in our example, and is simply there to be a bit more robust. | The fifth expression simply states “Find the line that starts with any number of capital letters, and insert a space afterwards”. I go a little more specific, and state “followed by any number of spaces and more letters”. However, it's not necessary in our example, and is simply there to be a bit more robust. | ||
- | **La cinquième expression indique tout simplement « Trouve la ligne qui commence avec un nombre quelconque de lettres majuscules et insère une espace après ». Je deviens plus précis en annonçant « suivi par un nombre quelconque d' | + | **La cinquième expression indique tout simplement « Trouve la ligne qui commence avec un nombre quelconque de lettres majuscules et insère une espace après ». Je deviens plus précis en annonçant « suivi par un nombre quelconque d' |
That about covers the steps I undertook in this scenario. I realize that this is a relatively specific occasion, and not everyone will want to have this exact formatting. My hope is that following my process will help you understand how to approach these sorts of problems. If it's wished for, I can spend an article focusing on short formatting problems, and working through it step by step. If anyone is interested in that sort of article, please let me know via email. As always, any questions/ | That about covers the steps I undertook in this scenario. I realize that this is a relatively specific occasion, and not everyone will want to have this exact formatting. My hope is that following my process will help you understand how to approach these sorts of problems. If it's wished for, I can spend an article focusing on short formatting problems, and working through it step by step. If anyone is interested in that sort of article, please let me know via email. As always, any questions/ | ||
- | **Et voilà pour les étapes par lesquelles je suis passé dans ce scenario. Mais je me rends compte que c'est un peu spécifique et que cet exercice de mise en forme détaillée ne va pas être utile à tout le monde. Néanmoins, j' | + | **Et voilà pour les étapes par lesquelles je suis passé dans ce scénario. Mais je me rends compte que c'est un peu spécifique et que cet exercice de mise en forme détaillée ne va pas être utile à tout le monde. Néanmoins, j' |
issue81/c_c.1399981856.txt.gz · Dernière modification : 2014/05/13 13:50 de auntiee