issue82:command_and_conquer
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue82:command_and_conquer [2014/05/05 17:11] – andre_domenech | issue82:command_and_conquer [2014/06/18 18:02] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | titre : Sed & Reader Survey | + | **Last month, I wrote an article on using regular expressions within |
- | Last month I received an email from John, a reader of C&C. He had turned to me for advice on using Sed to insert semi-colons within the text file created by Task Warrior. The reason he wanted to do this was to use the conkytext script to format the To-Do list nicely for his Conky. Included in the email was the file as created by Task Warrior. We then spent a couple of days putting together a functioning Sed script | + | Le mois dernier, j'ai écrit un article sur l' |
- | The Task | ||
- | We want to add a semi-colon after the contents | + | **His explanation: |
+ | • Take care of this one special case with the title line. As there is an address label (1), this substitution is done only for line 1. In sed scripts, | ||
+ | • Another address label (2). This rule is used only for line 2, and the command is branch | ||
+ | • The third line matches only the "tasks" line. | ||
+ | • The fourth line takes care of the semicolons after the dates, as there will never be two spaces due to right-adjustment. Note that you can also use delimiters other than slashes. | ||
+ | • Finally, take care of the rest. Substitute each at-least-two space combinations with a semicolon | ||
- | My Script | + | Son explication : |
- | Due to the fact that the script is rather long, as it offers extra functionality | + | • Prenez note du cas particulier concernant la ligne de titre, où la présence de l' |
- | The Thought Process | + | • Une autre étiquette d' |
- | There are a few things worth noting before we begin: | + | • La troisième ligne correspond uniquement à la ligne « tasks ». |
- | • The typical format of a sed command is: sed s/< | + | |
- | Sed calls replace “substitute”, | + | |
- | • Putting anything in \(\) will allow you to refer back to it on the RHS of the expression. | + | |
- | There are certain special characters that can be used in sed. We mainly need the “\s” expression, which stands for any space. | + | |
- | • Declaring a set number of repetitions can be done with: \{3\} for 3 repetitions, | + | |
- | • You must escape the semi-colon. | + | |
- | Some tips as to how I decide on each expression: | + | • La quatrième ligne traite les points-virgules après les dates en sachant qu'il n'y aura jamais deux espaces en raison de l'alignement à droite. Notez que vous pouvez également utiliser des délimiteurs autres que des barres obliques. |
- | • Figure out where you need to insert the character, as that defines where you group (in our case before the spaces, hence the second group is almost always started before the space character) | + | |
- | • Work bit-by-bit. Start with a simple sed command like: sed -e " | + | |
- | • If you have issues with step 2 because you can't get the regular expressions working, try using grep and the same regular expression. This lets you rule out the expression itself being wrong, and indicates it's a quirk of Sed's you haven' | + | |
- | • 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, | + | |
- | The Expressions | + | • Enfin, pour traiter le reste, remplacez toutes les combinaisons de doubles espaces (et plus) par un point-virgule. Cela s' |
- | first_expression=" | + | **His solution is certainly more efficient than mine, and is a brilliant example of how there are many solutions to these sorts of problems.** |
- | second_expression=" | + | |
- | third_expression=" | + | Sa solution est certainement plus efficace que la mienne, et c'est un brillant exemple qui prouve qu'il existe différentes manières de traiter ce genre de problème. |
- | fourth_expression=" | ||
- | fifth_expression=" | + | **Due to the fact that work has kept me extremely busy the last few weeks, I have decided to not write a typical article for this month. Instead, I'd like to run a vote on what article the readers would like to see in FCM#84. The reason why it will appear only in FCM#84, is due to the time frame between FCM being released, |
+ | • A reader has requested an in-depth article on installing & setting up Rails 4.0.2 on Ubuntu (Ruby on Rails) | ||
+ | • I recently installed ArchLinux to an external hard drive, capable of running on UEFI systems (Windows 8 or Mac OS X machines, mainly) | ||
+ | • Last month I also offered to set up an article with formatting problems to be solved using regular expressions | ||
- | The explanations | + | Puisque mon travail me tenait très occupé ces dernières semaines, j'ai décidé de ne pas écrire un article « normal » pour ce mois-ci. Au lieu de cela, je voudrais lancer un sondage à propos de l' |
- | The first expression tells Sed “Look for any character (a-z, A-Z, or 0-9), and see if it's followed by 2 or more spaces, then add a semi-colon before the spaces”. The trick to this is knowing that Sed can group matches to the regular expressions. This is why we have escaped brackets around the expressions. “\(a-zA-Z0-9]\)” then becomes match “\1” in the replacement section of Sed. We are essentially forming two groups – the character that precedes the spaces, and the spaces themselves. Then, in the replacement step, we're inserting a semi-colon between the two groups. This corresponds to column | + | • Un lecteur |
- | 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. | + | • J'ai récemment installé ArchLinux sur un disque dur externe, capable de fonctionner sur les systèmes UEFI ( Windows 8 ou Mac OS X machines, principalement) |
- | 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. | + | • Le mois dernier, j'ai également proposé de mettre en place un article avec des problèmes de mise en forme à résoudre en utilisant des expressions régulières et sed. |
- | 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 fifth expression simply states “Find the line that starts with any number of capital letters, and insert | + | **Naturally, anyone who has a preferred topic not listed above, is welcome to mark the “other” box, and to give me a brief description. Anyone |
- | 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/concerns or requests can be directed to me at lswest34+fcm@gmail.com. | + | Naturellement, pour ceux qui ont un sujet préféré qui ne figure pas ci-dessus, leur idée est la bienvenue, et vous pouvez cocher la case « autre » et me donner une brève description de ce que vous souhaiteriez. Toute personne est également invitée à indiquer son adresse e-mail dans le formulaire, afin que je puisse vous contacter pour des questions |
- | TABLEAUX (à traduire ?) | ||
- | Tableau 1 | + | **The link to the form: https:// |
- | Note: I've altered all entries in the file, for the sake of privacy. | + | Le lien vers le formulaire: https:// |
- | ID Project | ||
- | -- ----------- ---------- ------------------------------- ------- | ||
- | 3 Work 12/10/2013 Work Project | ||
- | 6 Work 12/12/2013 Submit 1st draft -2 days | ||
- | 10 Work 12/15/2013 Prepare Presentation | ||
- | 7 University | ||
- | 2 Hobby | ||
- | 4 Banking | ||
- | 1 Hobby | ||
- | 5 Programming 12/31/2013 Update Ruby on Rails Website | ||
- | 8 Work | ||
- | 9 Hobby 1/13/2014 Build Blu-Ray stand -4 wks | ||
- | |||
- | 10 tasks | ||
- | |||
- | Tableau 2 | ||
- | |||
- | |||
- | ID; Project; | ||
- | -- ----------- ---------- ------------------------------- ------- | ||
- | 3 Work; 12/10/2013; Work Project; | ||
- | 6 Work; 12/12/2013; Submit 1st draft; | ||
- | 10 Work; 12/15/2013; Prepare Presentation; | ||
- | 7 University; | ||
- | 2 Hobby; | ||
- | 4 Banking; | ||
- | 1 Hobby; | ||
- | 5 Programming; | ||
- | 8 Work; | ||
- | 9 Hobby; | ||
- | |||
- | ;;;10 tasks | ||
+ | **I apologize for not having a complete article for you this month. However, FCM#83 should contain a normal article next month. | ||
+ | ** | ||
+ | Je m' | ||
issue82/command_and_conquer.1399302702.txt.gz · Dernière modification : 2014/05/05 17:11 de andre_domenech