Solved

File editing script

Posted on 2014-03-17
1
148 Views
Last Modified: 2014-04-12
I need a program which makes the following changes to all the files in a directory and its subdirectories:

- replace "//" with "///", if the "//" is at the beginning of a line
- replace "//" with "///<" if the "//" is not at the beginning of a line.

I would be very grateful for any help.
0
Comment
Question by:Rothbard
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39935785
find directory -type f -print0 | xargs -0 perl -i.bak -pe 's#(?!^)//#///<#g; s#^//#///#'
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question