Differences between version 12 and revision by previous author of PerlOneLiners.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 12 | Last edited on Tuesday, December 16, 2003 9:24:05 pm | by AristotlePagaltzis | Revert |
Older page: | version 11 | Last edited on Tuesday, December 16, 2003 5:33:40 pm | by JohnMcPherson | Revert |
@@ -22,10 +22,12 @@
!! Replace literal "\n" and "\t" in a file with newlines and tabs
cat $file | perl -ne 's/\\n/\012/g; s/\\t/\011/g; print'
-(
This has a useless use of "
cat"
, and uses perl
-n (for no print) and
then does an explicit print.) This could
be rewritten as:
- perl -pe 's@\\n@\012@g; s@\\t@\011@g' < $file
-(you can use any punctuation as the separator in an s/// command, and if you have \ chars in your regexp then doing this can increase clarity.)
-----
+This has a useless use of __
cat__
, and uses __
-n__ but
then does an explicit print. You also don't need to use octal-coded character codes. It should
be rewritten as:
+ perl -pe 's!\\n!\n!g; s!\\t!\t!g' $file
+
+You can use any punctuation as the separator in an __s///__ command, and if you have backslashes or even need literal slashes in your pattern then doing this can increase clarity.
+
+----
AddToMe