how to remove the same text for many files at once

Joined
Feb 17, 2009
Messages
53
Reaction score
0
Points
6
hi have an string of text i want to remove from over 600 files is there any software that i can do this with on mac or maybe windows free would be best

cheers for your help
 
Joined
Jul 30, 2009
Messages
7,295
Reaction score
301
Points
83
Location
Wisconsin
Your Mac's Specs
Mac Mini (Late 2014) 2.6GHz Intel Core i5 Memory: 8GB 1600MHz DDR3
I can't imagine any software that will edit a file without having to open it. So that means opening 600 files. Sorry.
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
Moved to appropriate forum. Does not belong in anything goes.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,745
Reaction score
2,071
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
No software that I know of..but you can certainly do this from the command line with a little bit of scripting..SED comes to mind as the fastet way of doing it..

So for example..
Code:
for file in `ls`; do echo "Original - $file"; cat $file; cat $file | sed -e '/This is the third line/d' > .$file.tmp; echo "Changed - $file"; cat .$file.tmp; done
will produce the following:
Original - BAR
This is the sixth line
This is the seventh line
This is the third line
This is the tenth line
Changed - BAR
This is the sixth line
This is the seventh line
This is the tenth line

Original - FOO
This is the first line
This is the second line
This is the third line
This is the fourth line
Changed - FOO
This is the first line
This is the second line
This is the fourth line


Notice that the "This is the third line" has been deleted from both the FOO and BAR files..

Now I'm just using the string wholesale..but you can get creative with the regular expressions if need be..

Once you're satisified with the changes, you'd want to do add "mv .$file.tmp $file" as the last thing before "done" so that the modified file overwrites the original file..

Warning: Make a backup of your files before trying any of this!

Regards
 
Joined
Feb 26, 2010
Messages
2,116
Reaction score
123
Points
63
Location
Rocky Mountain High, Colorado
Your Mac's Specs
1.8 GHz i7 MBA 11" OSX 10.8.2
The standard file editors are sed, awk and grep - pretty much you can modify any text file(s) with a combination of these tools. Your question is unclear though - are you trying to get rid of text in the file or in the filename?
 
Joined
Sep 9, 2009
Messages
5,473
Reaction score
201
Points
63
Location
Down Under :D
Your Mac's Specs
Back to my old 2.2GHz C2D MB after selling my MBP and wondering what my next Mac will be :)
Automator comes to mind... I don't know if it's possible though, as I'm a bit of a novice with it, and only use it to rename multiple images..... So maybe an Automator Guru could shed some light :)
 
Joined
Mar 30, 2004
Messages
4,744
Reaction score
381
Points
83
Location
USA
Your Mac's Specs
12" Apple PowerBook G4 (1.5GHz)
The Multi-File Search option in TextWrangler (a freeware text editor) will allow you to replace text within a bunch of files.

Automator's "rename files" action will allow you to replace text in file names.

To remove text, you'd just replace the text with nothing (an empty string.)
 
Joined
Jul 30, 2009
Messages
7,295
Reaction score
301
Points
83
Location
Wisconsin
Your Mac's Specs
Mac Mini (Late 2014) 2.6GHz Intel Core i5 Memory: 8GB 1600MHz DDR3
The Multi-File Search option in TextWrangler (a freeware text editor) will allow you to replace text within a bunch of files.

That's cool. Does it then open those files to change the text string?
 
Joined
Mar 30, 2004
Messages
4,744
Reaction score
381
Points
83
Location
USA
Your Mac's Specs
12" Apple PowerBook G4 (1.5GHz)
That's cool. Does it then open those files to chang the text string?

Depends on what you mean by "open."

It does not (by default) display the contents files it modifies. Instead it produces a report at the end with a list of files, which you can either ignore and close, or use to review the files that got modified.

It does, technically, "open" each of the files in the background, invisibly.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top