This script cut size of files "Lol" change string in files

Basic:

find . -type f -name �*.txt�  -print | awk '{gsub("Ontem", "AntesdeOntem", $0); print > FILENAME}' *.txt

The idea is in folder /home/myapontamentos

I have some files and i need to change in all them the word "ontem" to "antesdeontem".

But bigger files are cut (size i mean) the file more bigger i have is 280Kb.

This script was send by a friend to help me but don't work, need "unixforum" fix, :rolleyes:

I try to "search" but all other's script's are diff, so...

If someone can help me, :smiley:

It sounds like you are substituting one word for another in the contents of the file, not the names of the file. That is, you aren't just renaming them, but editing them. Right?

Here is the way I think I would do it:

find . -type f -name �*.txt� -exec sed -i 's/Ontem/AntesdeOntem/g' '{}' \;

The -exec switch for find is kind of odd in that you need to terminate it with \;. It's just the way it is.

The -i switch for the sed command means to modify the files instead of printing the change to stdout.

yeap that's it, inside of .txt have "Ontem" and I want to change it to "AntesdeOntem" i try your's like this in just one file:

Aproximar.txt (this file is for testing have the sentence "Ontem fui buscar-te mas n�o estavas l�..." )

Now:

in console cd /home/apontamentos

then

./teste.sh
done

teste.sh

#!/bin/bash

find . -type f -name �*.txt� -exec sed -i 's/Ontem/AntesdeOntem/g' '{}' \;
echo "done"

But don't work "I still have Ontem" :frowning: and i must have:

"AntesdeOntem fui buscar-te mas n�o estavas l�..." )

:smiley: Can you please fix this? Many thanks, cu and regard's...

Probably your sed version doesn't support the -i option. Use a temporary file, and if you don't have to search in underlying directories you can avoid the use if find:

#!/bin/bash

for file in *.txt
do
  sed 's/Ontem/AntesdeOntem/g' "$file" > tempfile
  mv tempfile "$file"
done
echo "done"

Like this is working:


find . -type f -name �*.txt� -exec sed -i 's/Ontem/AntesdeOntem/g' {} \;

Don't ask me way but it is...

:smiley:

Thanks to all, more "Thanks unix.com Forum" :wink: