How to use the "sed" command to remove all lines that do not end up on the pattern?

1

2

How to use the "sed" command to remove all lines that do not end up on the pattern?

Example input:

aaa aaa.com
b b b b.txt
ccc ccc.gif
dd dd dd.txt

Looking for the pattern .txt,

I want to get:

b b b b.txt
dd dd dd.txt

Creek

Posted 2016-03-21T20:21:30.350

Reputation: 11

Answers

2

sed '/.txt/!d' test.txt

or to replace it in your file

sed -i '/.txt/!d' test.txt

but why dont you use a simple

grep  \.txt test.txt

here?

0x1ad1b88

Posted 2016-03-21T20:21:30.350

Reputation: 156

I'm doing something wrong.

`sed '/.txt/!d' $pn

printf '%s\n' "$pn" | while IFS= read -r line do printf "$line\n" done` – Creek – 2016-03-21T22:19:51.813