Answer the question
In order to leave comments, you need to log in
How to remove a template from all files?
Good afternoon. There are about 1000 almost identical html files. I need to remove a specific piece containing text and tags from each. I cut it manually from one file and saved it as remove.txt. How can I use this file as a template and cut it out of the rest of the files?
An important point: the piece to be cut does not begin with a new line and does not end with the end of the line either.
Answer the question
In order to leave comments, you need to log in
The string variable will receive a string from the file (did not check for complex constructions (the test was a short phrase)), then the loop will go through all the files in the specified folder and with each iteration write the file name to the var variable, sed -n will mute the output to stdout , by pattern from string will remove the lines in the file and write a new file without those lines. It works on the test bench, the key point remains what string will receive.
#!/bin/bash
string=$(cat /путь_до_файлов/remove.txt)
for var in $(ls -1 /путь_до_файлов)
do
sed -n "/$string/d" $var > /путь_до_новых_файлов/$var
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question