H
H
HAbRAhabp2016-04-13 19:03:09
linux
HAbRAhabp, 2016-04-13 19:03:09

Delete rows that do not contain a specific value?

There was a need to delete all lines from 10 files that do not contain
uk.html?subid=adwords
What is the best way to do this? Plain text files, in UTF-8

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2016-04-13
@HAbRAhabp

single file:
all files in directory:

ls /path/to/dir/* | while read file; do sed -i '/uk.html?subid=adwords/!d' "${file}"; done

V
vaut, 2016-04-13
@vaut

perl, awk, sed, grep -- choose what you like
for awk something like
For grep something like this:

grep -v "uk.html?subid=adwords" file > tmp && rm file && mv tmp file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question