London Smith London Smith - 1 year ago 89
Linux Question

Linux Sed and line break to add licence in php files

In order to add a licence to all php files, I would like to change


* Copyright (c) 2016-2017 My Project
* This file is part of My Project 1.2, more information at
* Licence another line
* Last line of licence

So I tested with sed on one file, for the first line of the licence:

sed -i -- 's/<?php/<?php\n\/*\n * Copyright(c) 2016-2017 My Project \n *\/ /g' index.php

It works but it adds some
at the end of each line of the file index.php and I don't understand why.

* Copyright(c) 2016-2017 My Project
*/ ^M
$page = 'home';^M

Thank you for your help

Answer Source

you can insert s/\r//; to delete a carriage return chars with your sed command

sed -i -- 's/\r//;s/<?php/<?php\n\/*\n * Copyright(c) 2016-2017 My Project \n *\/ /g' index.php 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download