Re: Means of trimming files
On Tue, 29 Jun 2004 19:50:25 -0400, Bill Moran <[EMAIL PROTECTED]> wrote: > > Gerard Samuel <[EMAIL PROTECTED]> wrote: > > > find ./ -name '*.php' -exec php -r '$f = file_get_contents("{}"); $h = > > fopen("{}", "wb"); fwrite($h, trim($f)); fclose($h);' \; > > > > It did the job perfectly. $ perl -0 -pi -e 's/\n+$//s' *.php will edit each .php file and replace it too. If you want a backup, then $ perl -0 -p -i.bak -e 's/\n+$//s' *.php Cheers Gautam ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
Gerard Samuel <[EMAIL PROTECTED]> wrote: > On Tuesday 29 June 2004 04:21 pm, Gerard Samuel wrote: > > So Ill start using truncate() for now, and start investigating perl. > > Thanks > > > > As I was writing the previous email, I thought about combining find with php's > cli interface and came up with this "dirty" command (all in one line) -> > > find ./ -name '*.php' -exec php -r '$f = file_get_contents("{}"); $h = > fopen("{}", "wb"); fwrite($h, trim($f)); fclose($h);' \; > > It did the job perfectly. Now _that's_ using the tools ... and the tools you know to boot! -- Bill Moran Potential Technologies http://www.potentialtech.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
On Tuesday 29 June 2004 04:21 pm, Gerard Samuel wrote: > So Ill start using truncate() for now, and start investigating perl. > Thanks > As I was writing the previous email, I thought about combining find with php's cli interface and came up with this "dirty" command (all in one line) -> find ./ -name '*.php' -exec php -r '$f = file_get_contents("{}"); $h = fopen("{}", "wb"); fwrite($h, trim($f)); fclose($h);' \; It did the job perfectly. ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
On Tuesday 29 June 2004 04:04 pm, Jerry McAllister wrote: > > On Tuesday 29 June 2004 01:07 pm, Bill Moran wrote: > > > Gerard Samuel <[EMAIL PROTECTED]> wrote: > > > > When editing php files, via the command line, there is a newline > > > > character after the closing ?> > > > > Im looking for a command that would trim files, so that I can append > > > > it to the find command. > > > > > > > > find ./ -name '*.php' -exec SOME_COMMAND {} \; > > > > > > If you're absolutely sure of the number of characters you're removing > > > from the end of the file, you could use truncate(1). > > > > > > Otherwise, you'll probably want sed or perl to check that it's not > > > removing important characters. > > > > Trying to use truncate is not working on my end. > > Does anyone see a syntax error with it??? > > Ran on 5.2.1-RELEASE-p6 FreeBSD. > > > > $ pwd > > /usr/home/gsam > > $ ls ~/z.php > > /home/gsam/z.php > > $ truncate -r ~/z.php > > usage: truncate [-c] -s [+|-]size[K|M|G] file ... > >truncate [-c] -r rfile file ... > > > > I tried $ truncate -r rfile ~/z.php but that didn't work either. > > Well is 'rfile' the exact length you want and is it always going to > be exactly a newline character shorter than z.php? > > Maybe you want something more like 'truncate -s -1 z.php' > presuming it is always just one newline character at the end. > > > Do you need to take the character only from the last line of the file or > from any line in the file that has it? > > If it is from any line, check out tr(1). > tr -d "\n" < z.php > z.php-clean > rm z.php > mv z.php-clean z.php > > Otherwise, I would be inclined to break out perl. > > jerry > Well although I can use a bit of perl within php, trying it via the command line is a bit of a learning curve, that I try to attempt to master it another day (after reading all those man pages :) ). Maybe if someone can suggest a how to page on the net, would be appreciated. But your suggestion on using 'truncate -s -1 z.php' worked as I would like it. The scenario Im trying to clean up is, if I were to create a file like this on the command line -> -- -- is actually -- \n -- on the file system. Which is normal. But Im trying to clean up the files to eliminate the trailing \n from the file, so that its consistent on the command line, and GUI editors, and to keep the hard core nuts off my back about having trailing space after the closing ?> So Ill start using truncate() for now, and start investigating perl. Thanks ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
> > On Tuesday 29 June 2004 01:07 pm, Bill Moran wrote: > > Gerard Samuel <[EMAIL PROTECTED]> wrote: > > > When editing php files, via the command line, there is a newline > > > character after the closing ?> > > > Im looking for a command that would trim files, so that I can append it > > > to the find command. > > > > > > find ./ -name '*.php' -exec SOME_COMMAND {} \; > > > > If you're absolutely sure of the number of characters you're removing from > > the end of the file, you could use truncate(1). > > > > Otherwise, you'll probably want sed or perl to check that it's not removing > > important characters. > > Trying to use truncate is not working on my end. > Does anyone see a syntax error with it??? > Ran on 5.2.1-RELEASE-p6 FreeBSD. > > $ pwd > /usr/home/gsam > $ ls ~/z.php > /home/gsam/z.php > $ truncate -r ~/z.php > usage: truncate [-c] -s [+|-]size[K|M|G] file ... >truncate [-c] -r rfile file ... > > I tried $ truncate -r rfile ~/z.php but that didn't work either. Well is 'rfile' the exact length you want and is it always going to be exactly a newline character shorter than z.php? Maybe you want something more like 'truncate -s -1 z.php' presuming it is always just one newline character at the end. Do you need to take the character only from the last line of the file or from any line in the file that has it? If it is from any line, check out tr(1). tr -d "\n" < z.php > z.php-clean rm z.php mv z.php-clean z.php Otherwise, I would be inclined to break out perl. jerry > Thanks ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
On Tuesday 29 June 2004 01:07 pm, Bill Moran wrote: > Gerard Samuel <[EMAIL PROTECTED]> wrote: > > When editing php files, via the command line, there is a newline > > character after the closing ?> > > Im looking for a command that would trim files, so that I can append it > > to the find command. > > > > find ./ -name '*.php' -exec SOME_COMMAND {} \; > > If you're absolutely sure of the number of characters you're removing from > the end of the file, you could use truncate(1). > > Otherwise, you'll probably want sed or perl to check that it's not removing > important characters. Trying to use truncate is not working on my end. Does anyone see a syntax error with it??? Ran on 5.2.1-RELEASE-p6 FreeBSD. $ pwd /usr/home/gsam $ ls ~/z.php /home/gsam/z.php $ truncate -r ~/z.php usage: truncate [-c] -s [+|-]size[K|M|G] file ... truncate [-c] -r rfile file ... I tried $ truncate -r rfile ~/z.php but that didn't work either. Thanks ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
On Tuesday 29 June 2004 01:07 pm, Bill Moran wrote: > Gerard Samuel <[EMAIL PROTECTED]> wrote: > > When editing php files, via the command line, there is a newline > > character after the closing ?> > > Im looking for a command that would trim files, so that I can append it > > to the find command. > > > > find ./ -name '*.php' -exec SOME_COMMAND {} \; > > If you're absolutely sure of the number of characters you're removing from > the end of the file, you could use truncate(1). > > Otherwise, you'll probably want sed or perl to check that it's not removing > important characters. Thanks. I'll see what I can come up with... ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Means of trimming files
Gerard Samuel <[EMAIL PROTECTED]> wrote: > When editing php files, via the command line, there is a newline character > after the closing ?> > Im looking for a command that would trim files, so that I can append it to the > find command. > > find ./ -name '*.php' -exec SOME_COMMAND {} \; If you're absolutely sure of the number of characters you're removing from the end of the file, you could use truncate(1). Otherwise, you'll probably want sed or perl to check that it's not removing important characters. -- Bill Moran Potential Technologies http://www.potentialtech.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Means of trimming files
When editing php files, via the command line, there is a newline character after the closing ?> Im looking for a command that would trim files, so that I can append it to the find command. find ./ -name '*.php' -exec SOME_COMMAND {} \; Thanks ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"