<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: My First Perl Script (TM)</title>
	<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM/</link>
	<description>Comments on Ask MetaFilter post My First Perl Script (TM)</description>
	<pubDate>Tue, 11 Nov 2008 10:35:40 -0800</pubDate>
	<lastBuildDate>Tue, 11 Nov 2008 10:35:40 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: My First Perl Script (TM)</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM</link>	
		<description>Please help me make a change to multiple .txt files using this funny computer code thing. &lt;br /&gt;&lt;br /&gt; I have a item I need to find and replace in 43 different text files.  As I understand it from &lt;a href=&quot;http://ask.metafilter.com/58846/How-can-I-find-and-replace-text-in-multiple-files&quot;&gt;this&lt;/a&gt;, it&apos;s possible to create a command that will do this for me.  The link mentions some options, but they are either for windows or assume a level of knowledge that I don&apos;t have.  Sad as it may sound, I have no idea where to put a command script on a MacBook Pro running OS Leopard 10.5. I&apos;ve tried to find a place or option in, say, the TextEdit application that lets you select a bunch of files and put in a command, but I can&apos;t find it. What would be a code I could use, and how would I implement it?&lt;br&gt;
&lt;br&gt;
For all of you who taught yourself Fortran as precocious eigh-year-olds, don&apos;t miss this opportunity to show a lady the wonders of technology.  It&apos;s just like teaching your grandmother to use email, except I&apos;m 34.&lt;br&gt;
&lt;br&gt;
Details: I need to change &quot;internet&quot; to &quot;Internet.&quot;</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2008:site.106537</guid>
		<pubDate>Tue, 11 Nov 2008 10:30:55 -0800</pubDate>
		<dc:creator>foxy_hedgehog</dc:creator>
		
			<category>findreplace</category>
		
			<category>find</category>
		
			<category>replace</category>
		
			<category>mac</category>
		
			<category>text</category>
		
			<category>word</category>
		
			<category>code</category>
		
			<category>script</category>
		
	</item> <item>
		<title>By: plexi</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537091</link>	
		<description>perl -pi -e &apos;s/old/new/g&apos; *.txt</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537091</guid>
		<pubDate>Tue, 11 Nov 2008 10:35:40 -0800</pubDate>
		<dc:creator>plexi</dc:creator>
	</item><item>
		<title>By: cellphone</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537097</link>	
		<description>You&apos;re going to want to run terminal.app, which is in Utlities in Applications.  From there you&apos;ll want to review any of the many references online regarding unix/linux/osx shells, specifically bash.  From there you can run any of those funny looking perl or sed commands.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537097</guid>
		<pubDate>Tue, 11 Nov 2008 10:38:37 -0800</pubDate>
		<dc:creator>cellphone</dc:creator>
	</item><item>
		<title>By: philomathoholic</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537102</link>	
		<description>The place to put perl one-liners (like plexi&apos;s) is on the command line, in Terminal. Open that, and paste plexi&apos;s example there.&lt;br&gt;
&lt;br&gt;
You&apos;ll have to change &quot;old&quot; to whatever you&apos;re looking to replace, and &quot;new&quot; to whatever you&apos;re looking to replace it with. So, if you&apos;re changing all instances of &quot;internet&quot; to &quot;Internet&quot;, then it will be &lt;code&gt;perl -e &apos;s/internet/Internet/g&apos; *.txt&lt;/code&gt; . This example assumes that all the files are in the current directory. If not, then either &lt;code&gt;cd&lt;/code&gt; to the current directory, or copy those files to your home directory.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537102</guid>
		<pubDate>Tue, 11 Nov 2008 10:44:00 -0800</pubDate>
		<dc:creator>philomathoholic</dc:creator>
	</item><item>
		<title>By: philomathoholic</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537107</link>	
		<description>Oh yeah, don&apos;t forget the &lt;code&gt;-pi&lt;/code&gt; after the &quot;perl&quot; in my example (like I did). The -p puts a loop around the one-liner, so that it gets executed more than once. The -i will edit those files in-place, rather printing out the new files. The -e let&apos;s you write a line of code on the command line, instead of putting it in a file (script).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537107</guid>
		<pubDate>Tue, 11 Nov 2008 10:49:14 -0800</pubDate>
		<dc:creator>philomathoholic</dc:creator>
	</item><item>
		<title>By: letourneau</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537124</link>	
		<description>Since you&apos;re a command-line neophyte, I&apos;d recommend having Perl make backups of the files it changes, which you can do by changing&lt;blockquote&gt;&lt;tt&gt;perl -pi -e &apos;s/internet/Internet/g&apos; *.txt&lt;/tt&gt;&lt;/blockquote&gt;to&lt;blockquote&gt;&lt;tt&gt;perl -pi.BAK -e &apos;s/internet/Internet/g&apos; *.txt&lt;/tt&gt;&lt;/blockquote&gt;Perl will put the original contents of &lt;tt&gt;foo.txt&lt;/tt&gt; into &lt;tt&gt;foo.txt.BAK&lt;/tt&gt; and do the substitutions in the original file. After you&apos;ve decided that Perl didn&apos;t screw anything up, you can throw the &lt;tt&gt;.BAK&lt;/tt&gt; files in the trash. (You can use any extension you want in place of &lt;tt&gt;.BAK&lt;/tt&gt;, by the way.)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537124</guid>
		<pubDate>Tue, 11 Nov 2008 11:02:16 -0800</pubDate>
		<dc:creator>letourneau</dc:creator>
	</item><item>
		<title>By: foxy_hedgehog</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537125</link>	
		<description>Wait, so if I pull up the Linux option on the Mac, all I need to do is type&lt;br&gt;
&lt;br&gt;
perl pi -e &apos;s/internet/Internet/g&apos; *.txt    &lt;br&gt;
&lt;br&gt;
on the Command line?&lt;br&gt;
&lt;br&gt;
How will it (the computer, Linux, God) know which text files I am applying the change to?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537125</guid>
		<pubDate>Tue, 11 Nov 2008 11:02:19 -0800</pubDate>
		<dc:creator>foxy_hedgehog</dc:creator>
	</item><item>
		<title>By: letourneau</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537134</link>	
		<description>&lt;i&gt;How will it (the computer, Linux, God) know which text files I am applying the change to?&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
The &lt;tt&gt;*.txt&lt;/tt&gt; means &quot;all files in the current directory ending in .txt&quot;, which you can get a list of by typing &lt;tt&gt;ls *.txt&lt;/tt&gt; at the command line. What you probably want to do is put all of the files you want to auto-replace stuff in into their own directory, so you can go into that directory and be sure you&apos;re working only on them. Suppose you make a subdirectory of your home Documents directory called &quot;fixme&quot; and put the files in there. Then you should do &lt;tt&gt;cd ~/Documents/fixme&lt;/tt&gt; to go into that directory, do &lt;tt&gt;ls *.txt&lt;/tt&gt; for good measure just to confirm that the files listed are the ones you want to change, and then you can run the Perl command described above.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537134</guid>
		<pubDate>Tue, 11 Nov 2008 11:08:16 -0800</pubDate>
		<dc:creator>letourneau</dc:creator>
	</item><item>
		<title>By: Wolfie</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537137</link>	
		<description>Most text editors will let you do this without code.  You&apos;re looking for find/replace in files functionality - usually under search or find in the menu.  I&apos;m on a PC not a Mac but I have to assume that shouldn&apos;t matter.  What were you using to create/edit these files?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537137</guid>
		<pubDate>Tue, 11 Nov 2008 11:11:14 -0800</pubDate>
		<dc:creator>Wolfie</dc:creator>
	</item><item>
		<title>By: phil</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537143</link>	
		<description>if you are uncomfortable using the command line there are &lt;a href=&quot;http://hexmonkeysoftware.com/&quot;&gt;graphical alternatives&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537143</guid>
		<pubDate>Tue, 11 Nov 2008 11:13:24 -0800</pubDate>
		<dc:creator>phil</dc:creator>
	</item><item>
		<title>By: formless</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537174</link>	
		<description>Like others have said, you&apos;ll need to run the Terminal application to run perl commands.&lt;br&gt;
&lt;br&gt;
When you first open up Terminal, it spawns a shell and puts you in your home or user directory.  The shell is just another way of interacting with Leopard, except instead of windows and mouse actions you type commands.  By default the shell Leopard runs is something called bash.  This isn&apos;t really important until you start getting into heavy command line usage, but it&apos;s good to know for reference, because some instructions will be different for bash, csh, tcsh or whatever shell you&apos;re running.&lt;br&gt;
&lt;br&gt;
The first thing you do once you open the terminal is change to the directory containing your files.  Although you can run the perl command from your home directory, it&apos;s probably easier if you&apos;re in the same directory as the files.  This way, you don&apos;t need to include the full path in the perl command.&lt;br&gt;
&lt;br&gt;
The &lt;strong&gt;cd&lt;/strong&gt; command lets you change directories (most common shell commands are very short).  You can type &lt;strong&gt;ls&lt;/strong&gt; to list the contents of the current directory.&lt;br&gt;
&lt;br&gt;
So, if your files are stored in the &lt;em&gt;Documents&lt;/em&gt; directory, you can type the following command:&lt;br&gt;
&lt;br&gt;
&lt;strong&gt;cd Documents&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
This will change to the &lt;em&gt;Documents&lt;/em&gt; directory, which is a subdirectory of your home directory.  Which just means the &lt;em&gt;Documents&lt;/em&gt; directory is inside your home directory&lt;br&gt;
&lt;br&gt;
You can type &lt;strong&gt;pwd&lt;/strong&gt; to see what your current directory is.  It will spit out whatever directory you&apos;re currently in.&lt;br&gt;
&lt;br&gt;
This is &lt;strong&gt;VERY&lt;/strong&gt; important: You should make a copy of all your files in the directory before you attempt to run the perl command.  Global search and replace from the command line is risky.  I&apos;ve nuked files myself many times.  Regular expressions, the language perl uses to perform search and replace, are very powerful, but also error-prone.  You can modify the perl command to backup the files by using &lt;strong&gt;perl -pi.bak -e ...&lt;/strong&gt; instead of &lt;strong&gt;perl -pi -e&lt;/strong&gt;, but it&apos;s probably just easier to copy the whole directory or individual files from the GUI.&lt;br&gt;
&lt;br&gt;
Once you&apos;re in the same directory as your files, you can run the perl command discussed above.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537174</guid>
		<pubDate>Tue, 11 Nov 2008 11:32:16 -0800</pubDate>
		<dc:creator>formless</dc:creator>
	</item><item>
		<title>By: MadamM</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537182</link>	
		<description>Just to lay a few things out for you: cd means change directory. ls basically lists the contents of the directory (folder) you&apos;re currently in. If your folder name has spaces in it, you&apos;ll want to put it in quotes. So, if your folder of text files that need fixin&apos; is in Documents/borkedfiles, you can just type cd Documents/borkedfiles after opening up Terminal. If they&apos;re in Documents/borked files, you&apos;ll need to type cd &quot;Documents/borked files&quot; to switch to that directory.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537182</guid>
		<pubDate>Tue, 11 Nov 2008 11:38:46 -0800</pubDate>
		<dc:creator>MadamM</dc:creator>
	</item><item>
		<title>By: netbros</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537186</link>	
		<description>&lt;a href=&quot;http://www.freewarefiles.com/BK-ReplacEm-V_program_262.html&quot;&gt;BK ReplaceEm&lt;/a&gt; is essentially a text search-and-replace program. However, unlike the search-replace functionality of a standard text editor, BK ReplaceEm is designed to operate on multiple files at once. And you need not only perform one search-replace operation per file -- you can setup a list of operations to perform. You can also specify a backup file for each file processed just in case the replace operation didn&apos;t do exactly what you wanted.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537186</guid>
		<pubDate>Tue, 11 Nov 2008 11:42:35 -0800</pubDate>
		<dc:creator>netbros</dc:creator>
	</item><item>
		<title>By: netbros</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537189</link>	
		<description>Oops, sorry. Windows only for BK ReplaceEM.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537189</guid>
		<pubDate>Tue, 11 Nov 2008 11:43:47 -0800</pubDate>
		<dc:creator>netbros</dc:creator>
	</item><item>
		<title>By: foxy_hedgehog</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537192</link>	
		<description>Most text editors will let you do this without code. You&apos;re looking for find/replace in files functionality - usually under search or find in the menu. I&apos;m on a PC not a Mac but I have to assume that shouldn&apos;t matter. What were you using to create/edit these files?&lt;br&gt;
&lt;br&gt;
&lt;em&gt;Once you&apos;re in the same directory as your files, you can run the perl command discussed above.&lt;br&gt;
&lt;/em&gt;&lt;br&gt;
When I&apos;m in the Linux mode, how do I go from documents to the specific file containing the docs I want to change?  &lt;br&gt;
&lt;br&gt;
Will every folder be a directory with a different name? Or in other words, will t the structure of the directories reflect the visual structure of windows on the Mac, with each separate folder, for example, &quot;Budget 06,&quot; &quot;Schoolwork,&quot; and &quot;How to Sabotage a Relationship&quot; each a distinct directory?&lt;br&gt;
&lt;br&gt;
Letourneau suggested, &lt;em&gt;&quot;What you probably want to do is put all of the files you want to auto-replace stuff in into their own directory, so you can go into that directory and be sure you&apos;re working only on them. Suppose you make a subdirectory of your home Documents directory called &quot;fixme&quot; and put the files in there. Then you should do cd ~/Documents/fixme to go into that directory, do ls *.txt for good measure just to confirm that the files listed are the ones you want to change, and then you can run the Perl command described above.&quot;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
How do I create one of these sub-directories that will show up in Linux?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;em&gt;Most text editors will let you do this without code. You&apos;re looking for find/replace in files functionality - usually under search or find in the menu. I&apos;m on a PC not a Mac but I have to assume that shouldn&apos;t matter. What were you using to create/edit these files?&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
I&apos;ve used TextEdit and TextWrangler. Neither of them seem to have this option- their &quot;Find/Replace&quot; only applies to the particular document you are working on.&lt;br&gt;
&lt;br&gt;
I know I sound as dumb as a box of hammers, but this is really interesting and I&apos;d like to be able to understand and implement it. Thank you...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537192</guid>
		<pubDate>Tue, 11 Nov 2008 11:45:14 -0800</pubDate>
		<dc:creator>foxy_hedgehog</dc:creator>
	</item><item>
		<title>By: foxy_hedgehog</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537197</link>	
		<description>&lt;em&gt;So, if your folder of text files that need fixin&apos; is in Documents/borkedfiles, you can just type cd Documents/borkedfiles after opening up Terminal. If they&apos;re in Documents/borked files, you&apos;ll need to type cd &quot;Documents/borked files&quot; to switch to that directory.&lt;br&gt;
&lt;/em&gt;&lt;br&gt;
Ah, ok- so you could get more elaborate from there to parallel your folders, eg: cd Documents/epicfailures/textfiles/wordchanges/filesthatspellinternetincorrectly&lt;br&gt;
&lt;br&gt;
and so on?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537197</guid>
		<pubDate>Tue, 11 Nov 2008 11:47:31 -0800</pubDate>
		<dc:creator>foxy_hedgehog</dc:creator>
	</item><item>
		<title>By: letourneau</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537203</link>	
		<description>&lt;i&gt;How do I create one of these sub-directories that will show up in Linux?&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
You can use the regular OS X Finder to do the initial prep work of moving the documents to be edited into their own directory (i.e. folder). The command line sees the same thing that the Finder sees.&lt;br&gt;
&lt;br&gt;
If you use Finder to create a folder inside your main Documents folder called &quot;fixme&quot;, and you drag the files you want to edit into that folder, after you open up the command line you can get there by typing &lt;tt&gt;cd ~/Documents/fixme&lt;/tt&gt; and then if you type &lt;tt&gt;ls&lt;/tt&gt; you should see the files you dragged in there. Then you can go ahead with the Perl business.&lt;br&gt;
&lt;br&gt;
&lt;i&gt;On preview:&lt;/i&gt; are you just editing a set of files, or are you trying to make edits across some files &lt;strong&gt;and subfolders with more files in them&lt;/strong&gt; as well? If the latter, the command line becomes a little more complicated.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537203</guid>
		<pubDate>Tue, 11 Nov 2008 11:53:41 -0800</pubDate>
		<dc:creator>letourneau</dc:creator>
	</item><item>
		<title>By: foxy_hedgehog</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537211</link>	
		<description>&lt;em&gt;On preview: are you just editing a set of files, or are you trying to make edits across some files and subfolders with more files in them as well? If the latter, the command line becomes a little more complicated.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
Nope.  Just a bunch of text files in one plain old folder.&lt;br&gt;
&lt;br&gt;
Thanks guys- I am excited to play with my new...er...toy!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537211</guid>
		<pubDate>Tue, 11 Nov 2008 12:00:26 -0800</pubDate>
		<dc:creator>foxy_hedgehog</dc:creator>
	</item><item>
		<title>By: letourneau</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537213</link>	
		<description>&lt;i&gt;I&apos;ve used TextEdit and TextWrangler. Neither of them seem to have this option- their &quot;Find/Replace&quot; only applies to the particular document you are working on.&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
Actually, &lt;a href=&quot;http://www.barebones.com/products/textwrangler/textwranglerpower.html&quot;&gt;this screenshot&lt;/a&gt; from TextWrangler looks like it can handle what you want to do. I bet the &quot;Multi-File Search&quot; checkbox at the bottom of the dialog lets you do find/replace across a collection of files at once.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537213</guid>
		<pubDate>Tue, 11 Nov 2008 12:01:46 -0800</pubDate>
		<dc:creator>letourneau</dc:creator>
	</item><item>
		<title>By: plexi</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537220</link>	
		<description>You can also do this on Mac command line:  say I am a nice computer</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537220</guid>
		<pubDate>Tue, 11 Nov 2008 12:09:24 -0800</pubDate>
		<dc:creator>plexi</dc:creator>
	</item><item>
		<title>By: zengargoyle</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537269</link>	
		<description>You might want to make that:&lt;br&gt;
&lt;br&gt;
perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos; *.txt&lt;br&gt;
&lt;br&gt;
The &apos;\b&apos;s make it match only &apos;internet&apos; alone as a full word.  So &quot;internetwork&quot; doesn&apos;t become &quot;Internetwork&quot; and &quot;thinternet&quot; doesn&apos;t become &quot;thInternet&quot;, but &quot;the internet, a wild place&quot; still gets changed to &quot;the Internet, a wild place&quot;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537269</guid>
		<pubDate>Tue, 11 Nov 2008 13:02:30 -0800</pubDate>
		<dc:creator>zengargoyle</dc:creator>
	</item><item>
		<title>By: 47triple2</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537277</link>	
		<description>Okay, this is something I don&apos;t think anybody&apos;s mentioned yet:&lt;br&gt;
&lt;br&gt;
If you don&apos;t want to type in the path to the folder, just type &quot;cd &quot; (cd + space) and drag in the folder that contains your text files. Terminal will auto-escape every space and other bad character.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537277</guid>
		<pubDate>Tue, 11 Nov 2008 13:09:09 -0800</pubDate>
		<dc:creator>47triple2</dc:creator>
	</item><item>
		<title>By: singingfish</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537293</link>	
		<description>Slightly more dangerous, but if say you had a bunch of text files in a directory heirarchy, rather than all in the same directory and you wanted to do soemthing to each of them, you can do this:&lt;br&gt;
&lt;br&gt;
find . -name &apos;*txt&apos; | xargs perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos; &lt;br&gt;
&lt;br&gt;
or to check that it&apos;s finding the right files first, do this:&lt;br&gt;
&lt;br&gt;
find . -name &apos;*txt&apos; | xargs echo perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos;&lt;br&gt;
&lt;br&gt;
The xargs command runs the following command on each item in the list generated by the previous command in the pipe.  So the find gets all files ending in .txt, and the output of this command is piped to xargs which runs the command perl -p -i -e ... on each file that is found.&lt;br&gt;
&lt;br&gt;
Unix is fun and time saving, but can be dangerous.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537293</guid>
		<pubDate>Tue, 11 Nov 2008 13:15:34 -0800</pubDate>
		<dc:creator>singingfish</dc:creator>
	</item><item>
		<title>By: foxy_hedgehog</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537296</link>	
		<description>&lt;em&gt;Actually, this screenshot from TextWrangler looks like it can handle what you want to do. I bet the &quot;Multi-File Search&quot; checkbox at the bottom of the dialog lets you do find/replace across a collection of files at once.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
Hey, thanks for that- I&apos;m going to try out this Perl thing and see if it just might work.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537296</guid>
		<pubDate>Tue, 11 Nov 2008 13:16:56 -0800</pubDate>
		<dc:creator>foxy_hedgehog</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537490</link>	
		<description>Also, the cool kids will snicker behind your back if you keep calling the OS X terminal &quot;Linux mode&quot;.  They all call it &quot;a bash shell running in a terminal&quot;. &lt;br&gt;
&lt;br&gt;
OS X and Linux both have this feature, and it works pretty much the same way on both, but doesn&apos;t mean that OS X&apos;s terminal belongs to Linux.  Both OS X and Linux inherited it from Unix.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537490</guid>
		<pubDate>Tue, 11 Nov 2008 15:50:20 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537517</link>	
		<description>&lt;em&gt;cd&amp;nbsp;Documents/epicfailures/textfiles/wordchanges/filesthatspellinternetincorrectly&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
Yes, that&apos;s the idea.&lt;br&gt;
&lt;br&gt;
In fact, Documents is itself a subfolder of your home folder, and the fact that the pathname you&apos;ve just mentioned after the &quot;cd&quot; doesn&apos;t &lt;em&gt;start&lt;/em&gt; with a slash means that it&apos;s relative to whatever folder you&apos;re cd&apos;d into right now.  So if you&apos;d done&lt;br&gt;
&lt;br&gt;
cd&amp;nbsp;Documents/epicfailures/textfiles/wordchanges/filesthatspellinternetincorrectly&lt;br&gt;
&lt;br&gt;
and then you subsequently try&lt;br&gt;
&lt;br&gt;
cd&amp;nbsp;Documents/hugesuccesses/textfiles/wordchanges/filesthatspellinternetincorrectly&lt;br&gt;
&lt;br&gt;
this will likely fail, because your filesthatspellinternetincorrectly folder probably &lt;em&gt;doesn&apos;t&lt;/em&gt; have a Documents folder inside &lt;em&gt;it&lt;/em&gt;.&lt;br&gt;
&lt;br&gt;
Every file on your computer has an &lt;em&gt;absolute&lt;/em&gt; pathname, identifying unambiguously where it is.  Absolute pathnames &lt;em&gt;start&lt;/em&gt; with a slash.&lt;br&gt;
&lt;br&gt;
You can find the absolute pathname of the current working directory at any time, using the pwd command.&lt;br&gt;
&lt;br&gt;
For example: when you first open a terminal, the current working directory will be your home folder (the one that &lt;em&gt;contains&lt;/em&gt; the Documents folder) and typing pwd might show you something like&lt;br&gt;
&lt;br&gt;
/home/foxy_hedgehog&lt;br&gt;
&lt;br&gt;
That would mean that the absolute pathname of your filesthatspellinternetincorrectly folder is&lt;br&gt;
&lt;br&gt;
/home/foxy_hedgehog/Documents/epicfailures/textfiles/wordchanges/filesthatspellinternetincorrectly&lt;br&gt;
&lt;br&gt;
You could stick that absolute pathname after cd &lt;em&gt;regardless&lt;/em&gt; of what your current working directory was, and it would take you to the right place.&lt;br&gt;
&lt;br&gt;
To make all this a little less painful, bash (the shell that&apos;s running in your terminal) has a few nice features you can use.  First off, cd by itself (with no pathname after it) will take you straight back to your home folder.&lt;br&gt;
&lt;br&gt;
Second, if you&apos;re in the process of entering a command and you hit the Tab key, the filename you&apos;re in the middle of typing will be auto-completed for you.  You could type&lt;br&gt;
&lt;br&gt;
cd Do[Tab]&lt;br&gt;
&lt;br&gt;
and you&apos;d instantly see&lt;br&gt;
&lt;br&gt;
cd Documents/&lt;br&gt;
&lt;br&gt;
appear on the command line, unless you also had a Dogs or Doughnuts folder, in which case you&apos;d hear a beep; type a c and hit Tab again and the auto-completion would then work.  You might be able to cd into your filesthatspell... directory with as little typing as&lt;br&gt;
&lt;br&gt;
cd Do[Tab]ep[Tab]te[Tab]w[Tab]f[Tab]&lt;br&gt;
&lt;br&gt;
Tab-completion totally rocks.  It&apos;s usually way faster than pointing and clicking.&lt;br&gt;
&lt;br&gt;
If you hit the up-arrow key, bash will step backwards through the commands you&apos;ve recently entered and allow you to re-enter any of them, possibly after editing it first.&lt;br&gt;
&lt;br&gt;
If you hit ctrl-R and type a few letters, bash will search backwards through your command history until it hits the most recent command containing those letters; subsequent ctrl-R keystrokes will repeat that search as many times as you like.&lt;br&gt;
&lt;br&gt;
Welcome to your computer&apos;s &lt;em&gt;literate&lt;/em&gt; user interface!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537517</guid>
		<pubDate>Tue, 11 Nov 2008 16:14:32 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: TheRaven</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537545</link>	
		<description>I use &lt;a href=&quot;http://www.hexmonkeysoftware.com/&quot;&gt;MassReplaceIt&lt;/a&gt; to do just this.  It&apos;s quick, it&apos;s easy and it&apos;s Mac.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537545</guid>
		<pubDate>Tue, 11 Nov 2008 16:33:43 -0800</pubDate>
		<dc:creator>TheRaven</dc:creator>
	</item><item>
		<title>By: suedehead</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537558</link>	
		<description>&lt;i&gt;If you don&apos;t want to type in the path to the folder, just type &quot;cd &quot; (cd + space) and drag in the folder that contains your text files. Terminal will auto-escape every space and other bad character.&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
Holy shit - this is awesome! Thanks a bunch!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537558</guid>
		<pubDate>Tue, 11 Nov 2008 16:55:36 -0800</pubDate>
		<dc:creator>suedehead</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537791</link>	
		<description>Hey, dragging and dropping files into the Terminal works in Ubuntu as well! Thanks for that tip, 47triple2.&lt;br&gt;
&lt;br&gt;
Tab completion will also supply whatever escapes are necessary for spaces and whatnot in file names.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537791</guid>
		<pubDate>Tue, 11 Nov 2008 20:37:03 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: zouhair</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1537988</link>	
		<description>&lt;a href=&quot;/106537/My-First-Perl-Script-TM#1537293&quot;&gt;singingfish&lt;/a&gt;: &quot;&lt;i&gt;Slightly more dangerous, but if say you had a bunch of text files in a directory heirarchy, rather than all in the same directory and you wanted to do soemthing to each of them, you can do this:&lt;br&gt;
&lt;br&gt;
find . -name &apos;*txt&apos; | xargs perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos; &lt;br&gt;
&lt;br&gt;
or to check that it&apos;s finding the right files first, do this:&lt;br&gt;
&lt;br&gt;
find . -name &apos;*txt&apos; | xargs echo perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos;&lt;br&gt;
...&lt;/i&gt;&quot;&lt;br&gt;
&lt;br&gt;
I&apos;d add -print0 so files with space in the name get handled well: &lt;br&gt;
&lt;br&gt;
find . -name &apos;*txt&apos; -print0 | xargs -0 perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1537988</guid>
		<pubDate>Wed, 12 Nov 2008 02:30:08 -0800</pubDate>
		<dc:creator>zouhair</dc:creator>
	</item><item>
		<title>By: letourneau</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1538018</link>	
		<description>I was thinking about bringing up the &lt;tt&gt;-print0&lt;/tt&gt; thing but it felt like going overboard in the context of this discussion. But I think by now we&apos;ve already decided to go down Overboard Road. Here&apos;s a way of avoiding having Perl generate .BAK files for files that aren&apos;t going to change...&lt;br&gt;
&lt;br&gt;
&lt;tt&gt;grep -Zrl &apos;/\binternet\b/&apos; . | xargs -0 perl -pi.BAK -e &apos;s/\binternet\b/Internet/g&apos;&lt;/tt&gt;&lt;br&gt;
&lt;br&gt;
You can drag-and-drop your target directory in place of the &lt;tt&gt;.&lt;/tt&gt; at the end of the &lt;tt&gt;grep&lt;/tt&gt; call and before the &lt;tt&gt;|&lt;/tt&gt; character.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1538018</guid>
		<pubDate>Wed, 12 Nov 2008 04:32:19 -0800</pubDate>
		<dc:creator>letourneau</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/106537/My-First-Perl-Script-TM#1540428</link>	
		<description>foxyhedgehog, in reply to your MeMail:&lt;br&gt;
&lt;br&gt;
First, the reason you&apos;d have trouble searching and replacing parentheses is because they do indeed have a special meaning.  The short answer is you need to use \( or \) wherever you find ( or ) failing to work.  Here&apos;s the &lt;a href=&quot;http://www.perl.com/doc/manual/html/pod/perlre.html&quot;&gt;long answer&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
Second, learning to use Perl isn&apos;t even slightly silly.  Perl borrows syntax and concepts from enough other languages that in the process of coming to grips with Perl you&apos;ll find yourself picking other things up in self-defence.  It&apos;s also a pretty good choice for knocking out quick write-only scripts to get specialized jobs done quickly and easily.  And despite the best efforts of its many detractors, and despite the existence of newer scripting languages that are arguably cleaner and easier to use, Perl is not going away any time soon.&lt;br&gt;
&lt;br&gt;
Don&apos;t worry about being &quot;not a programmer&quot;.  All it takes to learn how to write computer programs is an interest in doing so, an inquiring mind and practice, practice, practice.&lt;br&gt;
&lt;br&gt;
As for learning to &lt;a href=&quot;http://linuxcommand.org/index.php&quot;&gt;drive a Unix-family box using the command shell&lt;/a&gt;: in my opinion this is one of those things that everybody should learn along with their times tables, so I&apos;m clearly the wrong person to ask for advice about it :-)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.106537-1540428</guid>
		<pubDate>Thu, 13 Nov 2008 21:01:25 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item>
	</channel>
</rss>
