@
@
@eashla2016-01-19 19:00:24
bash
@eashla, 2016-01-19 19:00:24

How to edit multiple files at once?

Hey!
There are 50 html files. You need to add a line (link) to them in a certain place.

<a href="indexA.html">linkA</a>(сюда нужно вставить <a href="indexB.html">linkB</a>)<a href="indexС.html">linkС</a>

This code is present in all files. How to do this in bulk via the console or script?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2016-01-19
@saboteur_kiev

Try for example SED

A
Andrey San, 2016-01-19
@admusers

notepad++?

S
Slava Kryvel, 2016-01-19
@kryvel

for f in $(ls addr_with_files); do
 sed -i '/PATTERN/aNEW_LINE' $f;
done

PATTERN is the text of link A (if there are spaces or special characters in it, they need to be escaped with "\" )
NEW_LINE is the text of link B (if there are spaces or special characters in it, they need to be escaped with "\" )
addr_with_files - path to the folder with files
this script will add a new link after all links A in each file
I understand link A is unique in each file?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question