Re: DOS newlines (CR/LF) to Unix format [message #171734 is a reply to message #171731] |
Wed, 19 January 2011 11:33 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Bjarne Jensen wrote:
> I found this snippet on internet:
>
> # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
> awk '{sub(/\r$/,"");print}' # assumes EACH line ends with Ctrl-M
>
> It works fine on the commandline so I wrote like this in a php-script:
>
> - - -
>
> $unix = ".unix";
>
> foreach (glob($usedir."[12_]*") as $filename) {
> exec('awk { sub("/\r$", ""); print } $filename > $filename.$unix');
> }
>
> - - -
>
> But absolutely nothing happens!
Untrue.
> Why not?
Assuming that you are allowed to exec(): You should have copy-pasted; the
shell command is not the same. In essence, it is an awk(1) invocation
error: Unquoted `{' and `}' are for Brace Expansion in a POSIX-compatible
shell.
But you do not need a shell or awk(1) to accomplish what you want (although
dos2unix(1)/fromdos(1) is arguably faster than awk(1)), PHP has e.g.
fread(), preg_replace(), and fwrite().
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
|
|
|