Skip to content
Advertisement

Extracting lines by pattern matching from multiple files and writing them to another file in linux

I have 20 files. I want to extract lines by matching pattern '<script src="{%.*%}>' from those 20 files and write those lines to new file.

I also want to delete those lines from the original files.

Is there a better way to do it other than what I have tried which is terrible?

This is my attempt:

JavaScript

Advertisement

Answer

Using sed:

JavaScript

Sed‘s w command writes match to some other file. d deletes it.


example:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement