Re: Means of trimming files

From: Jerry McAllister (jerrymc_at_clunix.cl.msu.edu)
Date: 06/29/04

  • Next message: Beecher Rintoul: "Re: Which book should I start?"
    To: fbsd-questions@trini0.org (Gerard Samuel)
    Date: Tue, 29 Jun 2004 16:04:02 -0400 (EDT)
    
    

    >
    > On Tuesday 29 June 2004 01:07 pm, Bill Moran wrote:
    > > Gerard Samuel <fbsd-questions@trini0.org> 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
    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"


  • Next message: Beecher Rintoul: "Re: Which book should I start?"

    Relevant Pages

    • Re: What is going on?
      ... Problem is i do not know Perl. ... $#ARGV is the array index of the last variable entered. ... $epc variable plus a '/' character. ... Save the return value of the $response->content subroutine. ...
      (comp.lang.perl.misc)
    • Re: Dynamically updating perl variables
      ... character of multi-character parameter values. ... The intention was that, once the data was in a Perl data structure, the calling ... the case of your given data subroutine would return a list that, ... nice to see what a full alternative solution would look like using your ideas. ...
      (perl.beginners)
    • Re: writing binary files
      ... > Python or Perl, since your post referred to Python:-D ... looks as though it would require a template character to be passed for every ...
      (comp.lang.perl.misc)
    • Re: Parsing a file that has labels
      ... Let me explain the above perl code. ... As such a character doesn't exist that means the whole ... replace every occurrence of the regexp, ...
      (comp.unix.shell)
    • Re: dbi and utf8
      ... and a text-field "tmp" containing a single character, ... The following perl script behaves as if DBI or the ADO driver ... I have inserted a schwar using Microsoft® Access. ...
      (perl.dbi.users)