How to use sed to delete lines not containing pattern

Yves

I have a file as below:

Thumb Sri Lanka/Anuradhapura/Thumb Anuradhapura.jpg
Thumb Sri Lanka/Anuradhapura/vtour/panos/Anuradhapura.tiles/mobile/pano_b.jpg
Thumb Sri Lanka/Anuradhapura/vtour/panos/Anuradhapura.tiles/mobile/pano_d.jpg
Thumb Sri Lanka/Anuradhapura/vtour/panos/Anuradhapura.tiles/mobile/pano_f.jpg
Thumb Sri Lanka/Anuradhapura/vtour/panos/Anuradhapura.tiles/mobile/pano_l.jpg
Thumb Sri Lanka/Anuradhapura/vtour/panos/Anuradhapura.tiles/mobile/pano_r.jpg   
Thumb Sri Lanka/Anuradhapura/vtour/panos/Anuradhapura.tiles/mobile/pano_u.jpg
Thumb Sri Lanka/Anuradhapura/vtour/plugins/fps.xml
Thumb Sri Lanka/Anuradhapura/vtour/plugins/gyro2.js

I need to delete all lines except the first line, which means that lines should not be deleted if it contains Thumb[any characters except /].jpg.

I try to use sed to do this but I don't know how to write the regex.

I've tried like this: sed -i -e '.*Thumb^(/)\.jpg!d' file but it doesn't work.

Nino

If filename has to start with Thumb and then one or more charaters (without slash) and and with jpg, you can use regex like this one:

Thumb[^\/]*\.jpg

demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SED: delete lines containing first pattern and not containing second pattern

From Dev

Replacing lines containing a pattern with sed

From Dev

How to use sed to delete multiple lines when the pattern is matched and stop until the first blank line?

From Dev

Use SED to delete all lines between a single repeating pattern

From Dev

sed: How to delete lines matching a pattern that contains forward slashes?

From Dev

delete lines not (containing pattern and 2 lines above pattern)

From Dev

delete lines not (containing pattern and 2 lines above pattern)

From Dev

Delete lines containing pattern at the end of line

From Dev

Delete lines containing the pattern and the line before

From Dev

How to use sed to remove lines with pattern in square brackets

From Dev

sed: delete lines that match a pattern in a given field

From Dev

Delete range of lines above pattern with sed (or awk)

From Dev

How to delete lines containing backslash \

From Dev

How to detect and delete lines containing ˆ@

From Dev

How to use sed command to delete lines without backup file?

From Dev

How to delete multilines pattern with sed ?

From Dev

Use sed or awk to join lines in a certain pattern?

From Dev

use sed/awk to delete redundant lines

From Dev

SED: delete lines after pattern match while skipping a few lines, then delete the pattern line

From Dev

Use sed to delete all but a certain pattern

From Dev

How to Delete Lines Not Containing ":" in notepad++

From Dev

How do I use wildcard containing conditional pattern during sed substitution?

From Dev

sed - delete all lines that contain one pattern but not another

From Dev

Using sed to delete specific lines after LAST occurrence of pattern

From Dev

Extract lines containing a pattern

From Dev

How to find lines matching a pattern and delete them?

From Dev

How can I use sed\awk to look for certain lines within a file, and then match all subsequent lines that match a different pattern?

From Dev

How to use sed to delete timestamp pattern from a zero-terminated list of filenames

From Dev

How to use sed to delete timestamp pattern from a zero-terminated list of filenames

Related Related

  1. 1

    SED: delete lines containing first pattern and not containing second pattern

  2. 2

    Replacing lines containing a pattern with sed

  3. 3

    How to use sed to delete multiple lines when the pattern is matched and stop until the first blank line?

  4. 4

    Use SED to delete all lines between a single repeating pattern

  5. 5

    sed: How to delete lines matching a pattern that contains forward slashes?

  6. 6

    delete lines not (containing pattern and 2 lines above pattern)

  7. 7

    delete lines not (containing pattern and 2 lines above pattern)

  8. 8

    Delete lines containing pattern at the end of line

  9. 9

    Delete lines containing the pattern and the line before

  10. 10

    How to use sed to remove lines with pattern in square brackets

  11. 11

    sed: delete lines that match a pattern in a given field

  12. 12

    Delete range of lines above pattern with sed (or awk)

  13. 13

    How to delete lines containing backslash \

  14. 14

    How to detect and delete lines containing ˆ@

  15. 15

    How to use sed command to delete lines without backup file?

  16. 16

    How to delete multilines pattern with sed ?

  17. 17

    Use sed or awk to join lines in a certain pattern?

  18. 18

    use sed/awk to delete redundant lines

  19. 19

    SED: delete lines after pattern match while skipping a few lines, then delete the pattern line

  20. 20

    Use sed to delete all but a certain pattern

  21. 21

    How to Delete Lines Not Containing ":" in notepad++

  22. 22

    How do I use wildcard containing conditional pattern during sed substitution?

  23. 23

    sed - delete all lines that contain one pattern but not another

  24. 24

    Using sed to delete specific lines after LAST occurrence of pattern

  25. 25

    Extract lines containing a pattern

  26. 26

    How to find lines matching a pattern and delete them?

  27. 27

    How can I use sed\awk to look for certain lines within a file, and then match all subsequent lines that match a different pattern?

  28. 28

    How to use sed to delete timestamp pattern from a zero-terminated list of filenames

  29. 29

    How to use sed to delete timestamp pattern from a zero-terminated list of filenames

HotTag

Archive