<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.wiki.mohid.com/index.php?action=history&amp;feed=atom&amp;title=Perl_one-liners</id>
		<title>Perl one-liners - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.wiki.mohid.com/index.php?action=history&amp;feed=atom&amp;title=Perl_one-liners"/>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Perl_one-liners&amp;action=history"/>
		<updated>2026-04-04T20:17:35Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>http://www.wiki.mohid.com/index.php?title=Perl_one-liners&amp;diff=758&amp;oldid=prev</id>
		<title>Guillaume: 1 revision</title>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Perl_one-liners&amp;diff=758&amp;oldid=prev"/>
				<updated>2008-12-03T10:39:01Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 10:39, 3 December 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Guillaume</name></author>	</entry>

	<entry>
		<id>http://www.wiki.mohid.com/index.php?title=Perl_one-liners&amp;diff=757&amp;oldid=prev</id>
		<title>192.168.20.177 at 09:23, 30 January 2008</title>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Perl_one-liners&amp;diff=757&amp;oldid=prev"/>
				<updated>2008-01-30T09:23:28Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A lot of nice things can be said about [[Perl one-liners|one-liners]] in [[Perl]], but one example should suffice to give an understanding of their power and beauty:&lt;br /&gt;
&lt;br /&gt;
==One-liners==&lt;br /&gt;
The following line reads the STDIN, concatenates a line at the end and prints to STDOUT. Its useful to concatenate arguments in STDOUT before calling a command:&lt;br /&gt;
 &amp;gt;dir /B | perl -we&amp;quot;print&amp;lt;&amp;gt;;print'du'&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following line reads the filename.txt content as the standard input and outputs the substituted content:&lt;br /&gt;
 perl -p -e &amp;quot;s/old text/new text/gi;&amp;quot; &amp;lt; filename.txt&lt;br /&gt;
&lt;br /&gt;
The next line reads the filename.txt content and writes the substituted content&lt;br /&gt;
while keeping a backup of the original file (.bak):&lt;br /&gt;
 perl -pi.bak -e &amp;quot;s/old text/new text/gi;&amp;quot; filename.txt&lt;br /&gt;
&lt;br /&gt;
The next line reads an input file for a match. If match is found then splits the line by '/' char and prints the last element.&lt;br /&gt;
 perl -F\/ -lane perl &amp;quot;if (m|MATCH|{$a=pop @F; print $a;})&amp;quot; &amp;lt; input.txt&lt;br /&gt;
&lt;br /&gt;
The next lines reads input file and prints ok if a match is found:&lt;br /&gt;
 perl -nwe&amp;quot;if(m/MATCH/gi){print'Ok';}&amp;quot; &amp;lt; input.txt&lt;br /&gt;
&lt;br /&gt;
The next line reads stdinput, splits it, and prints it in uppercase:&lt;br /&gt;
 &amp;gt; echo EV_prefix.tmp | perl -F[_\.] -wlane'pop@F;$a=pop@F;print uc($a);'&lt;br /&gt;
 PREFIX&lt;br /&gt;
&lt;br /&gt;
The next line extracts values from xml tags:&lt;br /&gt;
 &amp;gt; curl http://www.cnn.com | perl -ne 'm/&amp;gt;([^&amp;lt;&amp;gt;]*?)&amp;lt;\// &amp;amp;&amp;amp; print$1.&amp;quot;\n&amp;quot;' | sed -e '/^$/d'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Utilities==&lt;br /&gt;
===Rename ''htm'' to ''html'' files===&lt;br /&gt;
In windows:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;dir /B /S | perl -wlne&amp;quot;/([^ ]+)\.htm$/i&amp;amp;&amp;amp;rename$1.'.htm',$1.'.html'&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In linux:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;find | grep htm | perl -wlne'/([^ ]+)\.htm$/i&amp;amp;&amp;amp;rename$1.&amp;quot;.htm&amp;quot;,$1.&amp;quot;.html&amp;quot;'&lt;br /&gt;
&lt;br /&gt;
===Copy files matching MATCH to SUBST===&lt;br /&gt;
In windows:&lt;br /&gt;
 &amp;gt;dir /B /S | perl -MFile::Copy -wlne&amp;quot;/(([^ ]+)MATCH([^ ]+))/&amp;amp;&amp;amp;copy$1,$2.'SUBST'.$3&amp;quot;&lt;br /&gt;
In linux:&lt;br /&gt;
 &amp;gt;find | grep MATCH | perl -MFile::Copy -wlne'/(([^ ]+)MATCH([^ ]+))/&amp;amp;&amp;amp;copy$1,$2.&amp;quot;SUBST&amp;quot;.$3'&lt;br /&gt;
&lt;br /&gt;
===Parsing MOHID code for keywords===&lt;br /&gt;
This little [[Perl one-liners|one-liner]] utility allows to parse MOHID code for keywords and default values:&lt;br /&gt;
 &amp;gt; more ModuleGeometry.F90 | perl -wlne&amp;quot;m/keyword.+'(.+)'/gi &amp;amp;&amp;amp; print $1; m/default.+=(.+),/gi &amp;amp;&amp;amp; print $1;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Lookahead and lookbehind===&lt;br /&gt;
This little perl program illustrates the use of ''lookahead''(?=) and ''lookbehind''(?&amp;lt;=) (as shown in I'mMike):&lt;br /&gt;
 $ perl -e '$num = 8927369280;'\&lt;br /&gt;
 &amp;gt; '$num =~ s/(?&amp;lt;=\d)(?=(\d\d\d)+$)/,/g;'\&lt;br /&gt;
 &amp;gt; 'print $num, &amp;quot;\n&amp;quot;'&lt;br /&gt;
 8,927,369,280&lt;br /&gt;
&lt;br /&gt;
==Troubleshoots==&lt;br /&gt;
 Q:Why my perl one-liners work in windows and don't work in linux, or vice-versa?&lt;br /&gt;
 A: Under windows you must encapsule the command in double-quotes (&amp;quot;&amp;quot;), &lt;br /&gt;
 whereas in linux you must encapsule commands in single-quotes (' ').&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Perl]]&lt;br /&gt;
*[[Regexp]]&lt;br /&gt;
*[[Bash]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;br /&gt;
[[Category:Windows]]&lt;br /&gt;
[[Category:Perl]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>192.168.20.177</name></author>	</entry>

	</feed>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-56589921-5', 'auto');
  ga('send', 'pageview');
</script>