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


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting This script cut size of files "Lol" change string in files
# 1  
Tools This script cut size of files "Lol" change string in files

Basic:

Code:
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, Smilie

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

If someone can help me, Smilie
# 2  
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:
Code:
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.
# 3  
Power hi KenJackson thanks for your help...

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 no estavas l..." )

Now:

in console cd /home/apontamentos

then

./teste.sh
done

teste.sh
Code:
#!/bin/bash

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

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

"AntesdeOntem fui buscar-te mas no estavas l..." )

Smilie Can you please fix this? Many thanks, cu and regard's...
# 4  
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:

Code:
#!/bin/bash

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

# 5  
Computer Hi Franklin52

Like this is working:

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

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

Smilie

Thanks to all, more "Thanks unix.com Forum" Smilie
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #435
Difficulty: Medium
Angular and AngularJS are web application frameworks to use for developing multi-page web applications.
True or False?

10 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

5. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

6. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

7. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

8. Shell Programming and Scripting

Delete files older than "x" if directory size is greater than "y"

I wrote a script to delete files which are older than "x" days, if the size of the directory is greater than "y" #!/bin/bash du -hs $1 while read SIZE ENTRY do if ; then find $1 -mtime +$2 -exec rm -f {} \; echo "Files older than $2 days deleted" else echo "free Space available"... (4 Replies)
Discussion started by: JamesCarter
4 Replies

9. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

10. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

Featured Tech Videos