How To Read Multiple Lines of User Input from the Command Line in Perl

Use Case: Export Apple Reminders from MacOS application to cleaned plain text, i.e. remove unwanted spaces, blank lines and square brackets
PROCEDURE
- Click on a single item in the MacOS Reminders app list
- Select All (either Command-a or use Edit->Select All)
- Copy (either Command-c or use Edit->Copy)
- Open Terminal
- Run cleanme
- Paste the copied reminders into the Terminal window, then press Control-D
- The script will output the cleaned list as plaintext
EXAMPLE
1 2 3 4 5 6 7 8 9 10 11 12 |
shell> ./cleanme [ ] Learn Python [ ] Create presentation [ ] Follow-up with customer ^D Learn Python Create presentation Follow-up with customer shell> |
Here is the Perl code I used to do it:
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/perl # cleanme use strict; use warnings; my @input = <STDIN>; foreach (@input) { next if /^\s+remind/; next if /^$/; s/^\[\s*\]\s*//; print; } |
Leave Your Comment
All fields marked with "*" are required.