W
W
warnerbrowsers2015-05-10 16:52:24
Perl
warnerbrowsers, 2015-05-10 16:52:24

How to edit multiple text files?

Good afternoon! Help with the task. There is a directory with a large number of text files of the same type (about 450). In each, you need to delete some pattern1, change pattern2 to pattern3. For one file, I found how to do it. what to do for all files in the directory?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
pcdesign, 2015-05-10
@pcdesign

perl -pi~ -e 's/foo/bar/g' *.html
Well, here's a one-liner.
Replaces foo with bar in all .html files.
Your problem is solved in 3 one-liners.
PS And this one-liner also saves the original files named html~.

S
Shaks, 2015-05-10
@shaks

uh..
1. get a list of files
2. cycle through them
3. add "the second file to the end of the first, the third to the end of the resulting one, etc."

E
Eugene, 2015-05-10
@yellowmew

Long but single line PowerShell
D:\test - folder where files are located
*.txt - file mask
D:\test\out.txt - general glued file after all edits

S
ShamblerR, 2015-05-15
@ShamblerR

If Linux then you can just on sh

<code>find /ПАПКА_ОТ КОТОРОЙ_ИСКАТЬ -type f -name "*.html" -exec sed -i 's/FOO/BAR/g' "{}" \;</code>

D
dionys, 2015-06-04
@dionys

This one-liner will suffice:
perl -p -e 's/foo/bar/g' *.txt > result.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question