Thread: Removing all instances of "NOT NULL" from an entire directory of files

Removing all instances of "NOT NULL" from an entire directory of files

From
"Dan Browning"
Date:
OK, I've got a command (or two) that will remove all NOT NULL strings from a
given file.

    cat filename | perl -pi -e "s/NOT NULL//g" > filename

But how do I run that command on every file in a directory, successively?

(In case you're wondering, I'm working on the pgsql/ directory of .sql files
that interchange uses to build the database tables).

Thanks,

Dan Browning
Network & Database Administrator
Cyclone Computer Systems


Re: Removing all instances of "NOT NULL" from an entire directory of files

From
"Michael R. Jinks"
Date:
Try this:

find /path/to/files -type f -exec perl -pi -e "s/NOT NULL//g" {} \;

Check the find(1) manpage for an explanation of the -exec directive.

HTH,
-m


On Mon, Sep 11, 2000 at 08:02:17PM -0400, rpjday wrote:
> On Mon, 11 Sep 2000, Dan Browning wrote:
>
> > OK, I've got a command (or two) that will remove all NOT NULL strings from a
> > given file.
> >
> >     cat filename | perl -pi -e "s/NOT NULL//g" > filename
> >
> > But how do I run that command on every file in a directory, successively?
> >
>
> whoa, the above perl program does NOT need to have input piped into it.
> all you need to say is:
>
> $ perl -pi -e "s/NOT NULL//g" file1 file2 file3 ...
>
>   one at a time, each file argument will be edited *in place*, saved
> back into the original file, and processing moves to the next file.
>
>   if you want to play it safe, use the option "-pi.BAK" instead, which
> will copy the original file to the name file.BAK (or whatever suffix
> you want) before doing the actual editing.
>
> rday
>
> p.s.  warning.  running any command on a file, and trying to redirect
> the new output back to the original file, is a recipe for DISASTER!
> most likely, due to the way redirection works, the file will be wiped
> and you will lose *all* of its contents.
>
>
>
> _______________________________________________
> Redhat-list mailing list
> Redhat-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/redhat-list

--
Michael Jinks, IB
Systems Administrator, CCCP
finger mjinks@embley.spc.uchicago.edu for public key
Vote Duke! http://www.entertaindom.com/pages/duke2000/home.jsp

Re: Removing all instances of "NOT NULL" from an entire directory of files

From
Jesus Aneiros
Date:
On Mon, 11 Sep 2000, Dan Browning wrote:

>     cat filename | perl -pi -e "s/NOT NULL//g" > filename
>
> But how do I run that command on every file in a directory, successively?

perl -i -pe 's/NOT NULL//g' *

The -i is doing the replacement in place so the pipe and redirection are
not necesary unless you want to keep the orginals, then you could use
-ibak

--
Jesus Aneiros Sosa
mailto:aneiros@jagua.cfg.sld.cu
http://jagua.cfg.sld.cu/~aneiros


Re: Removing all instances of "NOT NULL" from an entire directory of files

From
ERIC Lawson - x52010
Date:
(In tcsh; other shells have similar/equivalent syntax.)

At the shell prompt:

foreach i (*.sql)
echo $i
cp $i $i.bkp
end

I'm using echo and cp to illustrate the syntax only; your command(s) would
go in their place.

James Eric Lawson
Research Publications Editor III
National Simulation Resource

eric@bioeng.washington.edu

On Mon, 11 Sep 2000, Dan Browning wrote:

> OK, I've got a command (or two) that will remove all NOT NULL strings from a
> given file.
>
>     cat filename | perl -pi -e "s/NOT NULL//g" > filename
>
> But how do I run that command on every file in a directory, successively?
>
> (In case you're wondering, I'm working on the pgsql/ directory of .sql files
> that interchange uses to build the database tables).
>
> Thanks,
>
> Dan Browning
> Network & Database Administrator
> Cyclone Computer Systems
>
>