London Smith London Smith - 23 days ago 6
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

<?php
by:

<?php
/*
* Copyright (c) 2016-2017 My Project
* This file is part of My Project 1.2, more information at https://websitemyproject.com
* 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
^M
at the end of each line of the file index.php and I don't understand why.

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


Thank you for your help

Answer

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 
Comments