Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

remove words from mutiple files

 
Goto page 1, 2
   Linux (Home) -> Genreal Discussions RSS
Next:  Me linux gots a virus  
Author Message
Jesse Dorland

External


Since: Jul 13, 2008
Posts: 8



(Msg. 1) Posted: Mon Dec 29, 2008 6:57 pm
Post subject: remove words from mutiple files
Archived from groups: alt>linux (more info?)

I have downloaded some 100 astronomical files. All of the files have
words "Mr. Big". Is there a way to remove these words?
Back to top
Login to vote
Mysterious Traveler

External


Since: Aug 07, 2008
Posts: 5



(Msg. 2) Posted: Mon Dec 29, 2008 11:36 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Jesse Dorland wrote:
> I have downloaded some 100 astronomical files. All of the files have
> words "Mr. Big". Is there a way to remove these words?
If your word processor has a find and replace option, you can have it
find "Mr. Big" and in the replace field try using a space for the word.
In Windows I was able to do this by holding down the alt key and
pressing 255 on the keypad, this makes an invisible character that takes
the place of the words you want to get rid of, but in Linux those
characters can't be made. Maybe someone else can suggest a way, or you
could edit those text files running Windows.

Mysterious Traveler
Back to top
Login to vote
Dan C

External


Since: Jul 11, 2007
Posts: 232



(Msg. 3) Posted: Tue Dec 30, 2008 3:25 am
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mon, 29 Dec 2008 18:57:25 -0800, Jesse Dorland wrote:

> I have downloaded some 100 astronomical files. All of the files have
> words "Mr. Big". Is there a way to remove these words?

man sed


--
"Ubuntu" -- an African word, meaning "Slackware is too hard for me".
The Usenet Improvement Project: http://improve-usenet.org
Ahhhhhhh!: http://brandybuck.site40.net/pics/relieve.jpg
Back to top
Login to vote
Jesse Dorland

External


Since: Jul 13, 2008
Posts: 8



(Msg. 4) Posted: Tue Dec 30, 2008 5:41 am
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Dec 30, 12:36 am, Mysterious Traveler <mysterious_trave....RemoveThis@dot.net>
wrote:
> Jesse Dorland wrote:
> > I have downloaded some 100 astronomical files. All of the files have
> > words "Mr. Big". Is there a way to remove these words?
>
> If your word processor has a find and replace option, you can have it
> find "Mr. Big" and in the replace field try using a space for the word.
> In Windows I was able to do this by holding down the alt key and
> pressing 255 on the keypad, this makes an invisible character that takes
> the place of the words you want to get rid of, but in Linux those
> characters can't be made. Maybe someone else can suggest a way, or you
> could edit those text files running Windows.
>
> Mysterious Traveler

Well, my situation is bit more complicated. You see, in this folder I
have some 100 .doc files, and about 200 .jpg files. Inside all the doc
files, I have a word "Mr. Big", and then all the files names
(Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs
files.

So I want to remove not only from documents, but from files names too.
Back to top
Login to vote
Jesse Dorland

External


Since: Jul 13, 2008
Posts: 8



(Msg. 5) Posted: Tue Dec 30, 2008 5:49 am
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Dec 30, 4:06 am, "J.O. Aho" <u....DeleteThis@example.net> wrote:
> Mysterious Traveler wrote:
> > Jesse Dorland wrote:
> >> I have downloaded some 100 astronomical files. All of the files have
> >> words "Mr. Big". Is there a way to remove these words?
> > If your word processor has a find and replace option, you can have it
> > find "Mr. Big" and in the replace field try using a space for the word.
> > In Windows I was able to do this by holding down the alt key and
> > pressing 255 on the keypad, this makes an invisible character that takes
> > the place of the words you want to get rid of, but in Linux those
> > characters can't be made. Maybe someone else can suggest a way, or you
> > could edit those text files running Windows.
>
> The absolute fastest way is to use sed to remove the text.
>
> If using the slow and boring way, loading everything into a word processor
> like openoffice or using emacs, you use the replace function, only filling the
> search box, but not entering anything in the replace box (for you microsoft
> users, this works even in microsoft products).
>
> In the end is the question, do you want to do 100 load in, use replace and
> then save or type a short command line that will take care of all the files
> and remove the text, sed will be finished before you have loaded the word
> processor.


Do you know if it will remove the words from inside documents, or
files names as well?
Back to top
Login to vote
J.O. Aho

External


Since: Sep 03, 2006
Posts: 616



(Msg. 6) Posted: Tue Dec 30, 2008 10:06 am
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Mysterious Traveler wrote:
> Jesse Dorland wrote:
>> I have downloaded some 100 astronomical files. All of the files have
>> words "Mr. Big". Is there a way to remove these words?
> If your word processor has a find and replace option, you can have it
> find "Mr. Big" and in the replace field try using a space for the word.
> In Windows I was able to do this by holding down the alt key and
> pressing 255 on the keypad, this makes an invisible character that takes
> the place of the words you want to get rid of, but in Linux those
> characters can't be made. Maybe someone else can suggest a way, or you
> could edit those text files running Windows.

The absolute fastest way is to use sed to remove the text.

If using the slow and boring way, loading everything into a word processor
like openoffice or using emacs, you use the replace function, only filling the
search box, but not entering anything in the replace box (for you microsoft
users, this works even in microsoft products).

In the end is the question, do you want to do 100 load in, use replace and
then save or type a short command line that will take care of all the files
and remove the text, sed will be finished before you have loaded the word
processor.

--

//Aho
Back to top
Login to vote
J.O. Aho

External


Since: Sep 03, 2006
Posts: 616



(Msg. 7) Posted: Tue Dec 30, 2008 3:13 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Jesse Dorland wrote:

> Do you know if it will remove the words from inside documents, or
> files names as well?

sed will remove inside the file, if you want to replace the string in a
filename, you need to make a small shell script that reads the whole directory
and uses mv and sed together to rename the files that has the offending string
it's name.

--- remove string from filename ---
#!/bin/sh
for file in *
do
change_name_to=`echo $file | sed 's/Mr\. Big\//'`
mv "./$file" "./$change_name_to"
done
--- eof ---

This should fix that later problem, and it's space safe (it works with file
names with spaces too), with a bit of modification you can it to make both
changing the file content and the file name and allow you to use option which
allows you to use the script to replace what ever you want instead of the hard
coded "Mr. Big" thing.

--

//Aho
Back to top
Login to vote
jellybean stonerfish

External


Since: Jan 31, 2007
Posts: 38



(Msg. 8) Posted: Tue Dec 30, 2008 3:53 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 30 Dec 2008 05:41:17 -0800, Jesse Dorland wrote:

> On Dec 30, 12:36 am, Mysterious Traveler <mysterious_trave....TakeThisOut@dot.net>
> wrote:
>> Jesse Dorland wrote:
>> > I have downloaded some 100 astronomical files. All of the files have
>> > words "Mr. Big". Is there a way to remove these words?
>>
>> If your word processor has a find and replace option, you can have it
>> find "Mr. Big" and in the replace field try using a space for the word.
>> In Windows I was able to do this by holding down the alt key and
>> pressing 255 on the keypad, this makes an invisible character that
>> takes the place of the words you want to get rid of, but in Linux those
>> characters can't be made. Maybe someone else can suggest a way, or you
>> could edit those text files running Windows.
>>
>> Mysterious Traveler
>
> Well, my situation is bit more complicated. You see, in this folder I
> have some 100 .doc files, and about 200 .jpg files. Inside all the doc
> files, I have a word "Mr. Big", and then all the files names
> (Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs files.
>
> So I want to remove not only from documents, but from files names too.

You said you had text files, now you tell us it is .doc files. Big
difference.
Back to top
Login to vote
Stefan Patric

External


Since: Nov 12, 2005
Posts: 26



(Msg. 9) Posted: Tue Dec 30, 2008 5:04 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 30 Dec 2008 15:13:33 +0100, J.O. Aho wrote:

> Jesse Dorland wrote:
>
>> Do you know if it will remove the words from inside documents, or files
>> names as well?
>
> sed will remove inside the file, if you want to replace the string in a
> filename, you need to make a small shell script that reads the whole
> directory and uses mv and sed together to rename the files that has the
> offending string it's name.
>
> --- remove string from filename ---
> #!/bin/sh
> for file in *
> do
> change_name_to=`echo $file | sed 's/Mr\. Big\//'` mv "./$file"
> "./$change_name_to"
> done
> --- eof ---
>
> This should fix that later problem, and it's space safe (it works with
> file names with spaces too), with a bit of modification you can it to
> make both changing the file content and the file name and allow you to
> use option which allows you to use the script to replace what ever you
> want instead of the hard coded "Mr. Big" thing.

Easier would be to do two separate operations using wildcards to affect
all the files: First, sed to find and remove the text; then, rename
(instead of mv) to rename the files. Very fast. Very simple. No
scripting required.

Stef
Back to top
Login to vote
J.O. Aho

External


Since: Sep 03, 2006
Posts: 616



(Msg. 10) Posted: Tue Dec 30, 2008 5:55 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

jellybean stonerfish wrote:
> On Tue, 30 Dec 2008 05:41:17 -0800, Jesse Dorland wrote:

>> Well, my situation is bit more complicated. You see, in this folder I
>> have some 100 .doc files, and about 200 .jpg files. Inside all the doc
>> files, I have a word "Mr. Big", and then all the files names
>> (Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs files.
>>
>> So I want to remove not only from documents, but from files names too.
>
> You said you had text files, now you tell us it is .doc files. Big
> difference.

That depends on the version of the doc standard, most ms-doc files has the
text in plain text in the file, including font information in the begining of
each line, sed do work still well here, with latest revisions this may not be
true.

--

//Aho
Back to top
Login to vote
Chill Out

External


Since: Jan 11, 2007
Posts: 4



(Msg. 11) Posted: Tue Dec 30, 2008 7:12 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 30 Dec 2008 17:04:26 +0000, Stefan Patric wrote for every to
trash:

> On Tue, 30 Dec 2008 15:13:33 +0100, J.O. Aho wrote:
>
>> Jesse Dorland wrote:
>>
>>> Do you know if it will remove the words from inside documents, or
>>> files names as well?
>>
>> sed will remove inside the file, if you want to replace the string in a
>> filename, you need to make a small shell script that reads the whole
>> directory and uses mv and sed together to rename the files that has the
>> offending string it's name.
>>
>> --- remove string from filename ---
>> #!/bin/sh
>> for file in *
>> do
>> change_name_to=`echo $file | sed 's/Mr\. Big\//'` mv "./$file"
>> "./$change_name_to"
>> done
>> --- eof ---
>>
>> This should fix that later problem, and it's space safe (it works with
>> file names with spaces too), with a bit of modification you can it to
>> make both changing the file content and the file name and allow you to
>> use option which allows you to use the script to replace what ever you
>> want instead of the hard coded "Mr. Big" thing.
>
> Easier would be to do two separate operations using wildcards to affect
> all the files: First, sed to find and remove the text; then, rename
> (instead of mv) to rename the files. Very fast. Very simple. No
> scripting required.
>
> Stef

No mv is more efficient.
Back to top
Login to vote
Chill Out

External


Since: Jan 11, 2007
Posts: 4



(Msg. 12) Posted: Tue Dec 30, 2008 7:20 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 30 Dec 2008 05:41:17 -0800, Jesse Dorland wrote for every to
trash:

> On Dec 30, 12:36 am, Mysterious Traveler <mysterious_trave....TakeThisOut@dot.net>
> wrote:
>> Jesse Dorland wrote:
>> > I have downloaded some 100 astronomical files. All of the files have
>> > words "Mr. Big". Is there a way to remove these words?
>>
>> If your word processor has a find and replace option, you can have it
>> find "Mr. Big" and in the replace field try using a space for the word.
>> In Windows I was able to do this by holding down the alt key and
>> pressing 255 on the keypad, this makes an invisible character that
>> takes the place of the words you want to get rid of, but in Linux those
>> characters can't be made. Maybe someone else can suggest a way, or you
>> could edit those text files running Windows.
>>
>> Mysterious Traveler
>
> Well, my situation is bit more complicated. You see, in this folder I
> have some 100 .doc files, and about 200 .jpg files. Inside all the doc
> files, I have a word "Mr. Big", and then all the files names
> (Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs files.
>
> So I want to remove not only from documents, but from files names too.

That would be a good use for the rename feature if its in Ubuntu.

If not use Aho's example to rename the file during the mv step.

or here's an old example

#!/bin/sh
# renames files
if [ $# -eq 0 ] # if there is input
then
echo $1 "requires dir filenam/n";
exit
fi

for filename in $1 # Not necessary to use basename,
# since "*" won't return any file containing "/".

do n=`echo "$filename" | tr '[A-Z]' '{a-z}'`
# Variable substitution:

n=${n%/} # Removes trailing slash, added above, from filename.
[[ $filename == $n ]] || cp "$filename" "$n"
# Checks if filename already lowercase.
[[ $filename == $n ]] || echo "$filename" " moved to " "$n" >> /tmp/
fmtfile.ans
# Prints changed filenames
done
Back to top
Login to vote
jellybean stonerfish

External


Since: Jan 31, 2007
Posts: 38



(Msg. 13) Posted: Tue Dec 30, 2008 9:03 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 30 Dec 2008 17:55:25 +0100, J.O. Aho wrote:

> jellybean stonerfish wrote:
>> On Tue, 30 Dec 2008 05:41:17 -0800, Jesse Dorland wrote:
>
>>> Well, my situation is bit more complicated. You see, in this folder I
>>> have some 100 .doc files, and about 200 .jpg files. Inside all the doc
>>> files, I have a word "Mr. Big", and then all the files names
>>> (Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs
>>> files.
>>>
>>> So I want to remove not only from documents, but from files names too.
>>
>> You said you had text files, now you tell us it is .doc files. Big
>> difference.
>
> That depends on the version of the doc standard, most ms-doc files has
> the text in plain text in the file, including font information in the
> begining of each line, sed do work still well here, with latest
> revisions this may not be true.

When I did my test, using sed, on .doc files I created with openoffice, I
found it works if the strings are the same length, but fails if the
strings are different lengths.

sed 's/Big/Abc/' file.doc ::: WORKS
sed 's/Big/Ab/' file.doc ::: DOES NOT WORK

stonefish
Back to top
Login to vote
J.O. Aho

External


Since: Sep 03, 2006
Posts: 616



(Msg. 14) Posted: Tue Dec 30, 2008 11:10 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

jellybean stonerfish wrote:
> On Tue, 30 Dec 2008 17:55:25 +0100, J.O. Aho wrote:
>
>> jellybean stonerfish wrote:
>>> On Tue, 30 Dec 2008 05:41:17 -0800, Jesse Dorland wrote:
>>>> Well, my situation is bit more complicated. You see, in this folder I
>>>> have some 100 .doc files, and about 200 .jpg files. Inside all the doc
>>>> files, I have a word "Mr. Big", and then all the files names
>>>> (Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs
>>>> files.
>>>>
>>>> So I want to remove not only from documents, but from files names too.
>>> You said you had text files, now you tell us it is .doc files. Big
>>> difference.
>> That depends on the version of the doc standard, most ms-doc files has
>> the text in plain text in the file, including font information in the
>> begining of each line, sed do work still well here, with latest
>> revisions this may not be true.
>
> When I did my test, using sed, on .doc files I created with openoffice, I
> found it works if the strings are the same length, but fails if the
> strings are different lengths.
>
> sed 's/Big/Abc/' file.doc ::: WORKS
> sed 's/Big/Ab/' file.doc ::: DOES NOT WORK

OpenOffice and StarOffice differs from ms-office in the way they create the
doc files, just take one saved with ms-office, open it in OO and then save it
with another file, and then do a 'ls -l' on both files, the original made with
ms-office and the one saved with OO, you will see atleast 25% difference on
the file size.

--

//Aho
Back to top
Login to vote
jellybean stonerfish

External


Since: Jan 31, 2007
Posts: 38



(Msg. 15) Posted: Tue Dec 30, 2008 11:42 pm
Post subject: Re: remove words from mutiple files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 30 Dec 2008 23:10:54 +0100, J.O. Aho wrote:

> jellybean stonerfish wrote:
>> On Tue, 30 Dec 2008 17:55:25 +0100, J.O. Aho wrote:
>>
>>> jellybean stonerfish wrote:
>>>> On Tue, 30 Dec 2008 05:41:17 -0800, Jesse Dorland wrote:
>>>>> Well, my situation is bit more complicated. You see, in this folder
>>>>> I have some 100 .doc files, and about 200 .jpg files. Inside all the
>>>>> doc files, I have a word "Mr. Big", and then all the files names
>>>>> (Saturn_Mr.Big.doc), (Venus_Mr.Big.doc), and same goes for .jpgs
>>>>> files.
>>>>>
>>>>> So I want to remove not only from documents, but from files names
>>>>> too.
>>>> You said you had text files, now you tell us it is .doc files. Big
>>>> difference.
>>> That depends on the version of the doc standard, most ms-doc files has
>>> the text in plain text in the file, including font information in the
>>> begining of each line, sed do work still well here, with latest
>>> revisions this may not be true.
>>
>> When I did my test, using sed, on .doc files I created with openoffice,
>> I found it works if the strings are the same length, but fails if the
>> strings are different lengths.
>>
>> sed 's/Big/Abc/' file.doc ::: WORKS sed 's/Big/Ab/' file.doc
>> ::: DOES NOT WORK
>
> OpenOffice and StarOffice differs from ms-office in the way they create
> the doc files, just take one saved with ms-office, open it in OO and
> then save it with another file, and then do a 'ls -l' on both files, the
> original made with ms-office and the one saved with OO, you will see
> atleast 25% difference on the file size.

That's ok. I rarely create a .doc file.
Editing the .doc files with sed, as the op asked sounds like the wrong
solution.
I would eliminate the .doc files from the equation.

wvText Saturn_Mr.Big.doc Saturn.txt
sed -ie 's/Mr. Big//' Saturn.txt
Back to top
Login to vote
Display posts from previous:   
Related Topics:
remove drm from wmv files - Hi all, mplayer sometimes doesn't play wmv files, and I suspect its because they have drm. The screen becomes green and garbled. Does anyone know of a way to remove drm from wmv files? It would have to work on linux. iksrazal

Command line to remove duplicate files? - I have a Fedora 6 system and want to remove some duplicate files. I have about 1,500 jpg images on my XP machine on the LAN and setup the directory containing the photos as a share, then mounted it in Linux with cifs, so now I can use Linux tools on..

How to remove files created by 'mknod'? (kernel version 2... - Hi all, I cannot delete files created by 'mknod'. I used a subdir in my home directory (NFS mounted) as a staging area for Linux filesystem contents that were used as inputs to mkfs.* utilities. Now I am done and want to get rid of all the files, for...

IS THE BIBLE GOD'S WORDS!!! - IS THE BIBLE GOD'S WORDS!!! In RSV Bible see the sixth paragraph of the preface (for example only you can complete reading and discovering by yourself): YET THE KING JAMES VERSION HAS GRAVE DEFECTS. By the middle of the nineteenth century, the..

How to count words in a postscript file? - Is there a command to do it? I tried "wc -w file.ps". It did not work. Thanks a lot.
       Linux (Home) -> Genreal Discussions All times are: Pacific Time (US & Canada) (change)
Goto page 1, 2
Page 1 of 2

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
  Linux Forums
 Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact