a find command problem

a find command problem

Post by Pete » Thu, 20 Jun 2002 11:30:57



Hello
   I suppose the following command will change every 'oslib' to
'stdio' in file a.

   But it doesn't work. Because it change every 'oslib' to 'stdio' and
place it into a new file '{}'

would you like to tell me how to fix it?

thanks

 
 
 

a find command problem

Post by Bill Marc » Thu, 20 Jun 2002 14:18:45


On 18 Jun 2002 19:30:57 -0700,

>Hello
>   I suppose the following command will change every 'oslib' to
>'stdio' in file a.

What following command?  Are you trying to change file names or text
inside a file?
>   But it doesn't work. Because it change every 'oslib' to 'stdio' and
>place it into a new file '{}'

>would you like to tell me how to fix it?

>thanks



 
 
 

a find command problem

Post by William Par » Thu, 20 Jun 2002 15:36:45



> Hello
>   I suppose the following command will change every 'oslib' to 'stdio' in
>   file a.

>   But it doesn't work.  Because it change every 'oslib' to 'stdio' and
>   place it into a new file '{}'

What doesn't work?  Care to give us few hints, or should we take wild
guesses and give you random answers?

> would you like to tell me how to fix it?

> thanks


--

8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin
 
 
 

a find command problem

Post by David Vidal RodrĂ­gue » Fri, 21 Jun 2002 04:26:39



> Hello
>    I suppose the following command will change every 'oslib' to
> 'stdio' in file a.

I don't know which command you have typed but the _following_ does the
trick (writes to the standard output):

$ sed -e 's/oslib/stdio/g' a

where a is the file you wish to execute the substitution.
Regards!
David

 
 
 

a find command problem

Post by Jon Langset » Fri, 21 Jun 2002 04:47:40



>> Hello
>>    I suppose the following command will change every 'oslib' to
>> 'stdio' in file a.

> I don't know which command you have typed but the _following_ does the
> trick (writes to the standard output):

> $ sed -e 's/oslib/stdio/g' a

> where a is the file you wish to execute the substitution.

Alternatively:

shell> cat a | sed 's/oslib/stdio/g' > b

Which saves the corrected file to file "b"

--
Jon Langseth

 
 
 

a find command problem

Post by Pete » Fri, 21 Jun 2002 10:38:10




> > Hello
> >   I suppose the following command will change every 'oslib' to 'stdio' in
> >   file a.

> >   But it doesn't work.  Because it change every 'oslib' to 'stdio' and
> >   place it into a new file '{}'

> What doesn't work?  Care to give us few hints, or should we take wild
> guesses and give you random answers?

> > would you like to tell me how to fix it?

> > thanks


Sorry, i forgot to post that command:

find file_a -exec sed s/oslib/stdio/ {} > {}

It should change every oslib to stdio in file_a and save it to file_a.
But it saved to file {}. It seen "find" doesn't convert the second {}
to the file name it found

This command doesn't work
thanks

 
 
 

a find command problem

Post by Dave Bro » Fri, 21 Jun 2002 11:49:48



> Sorry, i forgot to post that command:

> find file_a -exec sed s/oslib/stdio/ {} > {}

> It should change every oslib to stdio in file_a and save it to file_a.
> But it saved to file {}. It seen "find" doesn't convert the second {}
> to the file name it found

> This command doesn't work

Commands only work if they are used with the proper syntax.  Apparently  
you haven't looked at the manpage, nor looked through the books in  
your Unix library for examples of using the "find" command.  Trial and
error will take you forever, and this is just for one command.

  find <starting_directory> -name file_a
    -exec sed 's/oslib/stdio/' {} > {}.new \;

            (above command typed all on one line)

This will edit all files named "file_a" but giving the resulting
edited file the name file_a.new.  ("sed" does not do an "inplace"
edit.)  The terminating "\;" for the "-exec" element is required.

The Gnu version of find does allow the <starting directory> to
be omitted, in which case the current directory is used as the
starting point for the search.

--
Dave Brown  Austin, TX

 
 
 

a find command problem

Post by William Par » Fri, 21 Jun 2002 14:16:55




>> Sorry, i forgot to post that command:

>> find file_a -exec sed s/oslib/stdio/ {} > {}
>  find <starting_directory> -name file_a
>    -exec sed 's/oslib/stdio/' {} > {}.new \;

{} should be escaped like \{\} or '{}', otherwise shell complains.  But,
why not just do
    sed 's/oslib/stdio/g' file_a > tmp && mv tmp file_a

And, if you have to search for files to process, then do
    find . -type f -name '...' | while read a; do
        sed 's/oslib/stdio/g' $a > tmp && mv tmp $a
    done

--

8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin

 
 
 

a find command problem

Post by Dave Bro » Fri, 21 Jun 2002 15:46:52



> {} should be escaped like \{\} or '{}', otherwise shell complains.  But,
> ...

Neither bash nor ksh complains; I don't know about others.  These
are not metacharacters which bash or ksh affects (by expansion,  
substitution, etc.) so they get passed to the find command undisturbed.  
If they needed to be escaped, I would have escaped them. :)

--
Dave Brown  Austin, TX

 
 
 

a find command problem

Post by Pete » Sat, 22 Jun 2002 12:38:43




> > Sorry, i forgot to post that command:

> > find file_a -exec sed s/oslib/stdio/ {} > {}

> > It should change every oslib to stdio in file_a and save it to file_a.
> > But it saved to file {}. It seen "find" doesn't convert the second {}
> > to the file name it found

> > This command doesn't work

> Commands only work if they are used with the proper syntax.  Apparently  
> you haven't looked at the manpage, nor looked through the books in  
> your Unix library for examples of using the "find" command.  Trial and
> error will take you forever, and this is just for one command.

>   find <starting_directory> -name file_a
>     -exec sed 's/oslib/stdio/' {} > {}.new \;

>             (above command typed all on one line)

> This will edit all files named "file_a" but giving the resulting
> edited file the name file_a.new.  ("sed" does not do an "inplace"
> edit.)  The terminating "\;" for the "-exec" element is required.

> The Gnu version of find does allow the <starting directory> to
> be omitted, in which case the current directory is used as the
> starting point for the search.

Sorry, doesn't work.  It will not saved to file_a.new.   It saved to {}.new
thank anyway

 
 
 

a find command problem

Post by Dave Bro » Sat, 22 Jun 2002 13:28:36




>> Commands only work if they are used with the proper syntax.  Apparently  
>> you haven't looked at the manpage, nor looked through the books in  
>> your Unix library for examples of using the "find" command.  Trial and
>> error will take you forever, and this is just for one command.

>>   find <starting_directory> -name file_a
>>     -exec sed 's/oslib/stdio/' {} > {}.new \;

>>             (above command typed all on one line)

> Sorry, doesn't work.  It will not saved to file_a.new.   It saved to {}.new
> thank anyway


Aha!  The exec statement can't do redirection!  (Quoting the exec
statement didn't seem to help.)

So lets use a command that does inplace editing:

  find . -name file_a -exec perl -pi -e 's/oslib/stdio/' {} \;

Seems a shame to have exec perl each time.  If it were something
other than a one-shot deal, it would probably better be done by finding
all the files first, putting their pathnames in a file, then writing
a perl script to do the processing in a single execution.

--
Dave Brown  Austin, TX

 
 
 

a find command problem

Post by Pete » Sun, 23 Jun 2002 10:45:22





> >> Commands only work if they are used with the proper syntax.  Apparently  
> >> you haven't looked at the manpage, nor looked through the books in  
> >> your Unix library for examples of using the "find" command.  Trial and
> >> error will take you forever, and this is just for one command.

> >>   find <starting_directory> -name file_a
> >>     -exec sed 's/oslib/stdio/' {} > {}.new \;

> >>             (above command typed all on one line)

> > Sorry, doesn't work.  It will not saved to file_a.new.   It saved to {}.new
> > thank anyway


Oic, Thank you very much of the helps....
thanks

- Show quoted text -

Quote:> Aha!  The exec statement can't do redirection!  (Quoting the exec
> statement didn't seem to help.)

> So lets use a command that does inplace editing:

>   find . -name file_a -exec perl -pi -e 's/oslib/stdio/' {} \;

> Seems a shame to have exec perl each time.  If it were something
> other than a one-shot deal, it would probably better be done by finding
> all the files first, putting their pathnames in a file, then writing
> a perl script to do the processing in a single execution.

 
 
 

1. Need to find vi command to remove ^H from command man find > find.txt

hi there,

Q1: i need to find out the vi command needed to change all occurences of
some character followed by a backspace to nothing.  that is to remove the ^H
sequence created by the following command man find > find.txt .
Q2:can sed perform the same task as vi?

Q3:what would be the command also for sed ?

thanks.

Iskandar

2. Format of pre-formatted tape for Wangtek 3080T

3. need to pipe a find or locate command into the rm command....PLEASE help!

4. Linux Porting

5. CLUB: Linux User Group of Davis, Feb. 21st, "GDB - The GNU Debugger"

6. Piping results of a 'find' command to a 'mv' command...

7. LMS/Phillips CM-205 CDROM Support

8. Linux Commands- Where can i find list of Linux Commands for the console?

9. Need to find info on the 'FIND' command

10. find command to find files of a certain date

11. "find" command to find file on specific date?