octosquidopus
octosquidopus

Reputation: 3713

sed: remove lines before A and after Z in file

Using sed, I'm trying to remove everything before a defined pattern and everything after a different one.

head and tail don't quite cut it because they just remove lines, not characters.

From:

0
0
0A
Z0
)
>

To:

A
Z

Upvotes: 0

Views: 150

Answers (1)

Birei
Birei

Reputation: 36262

One way:

sed -ne '
    /A/,/Z/ {
        /A/ s/^[^A]*//;
        /Z/ s/\(Z\).*$/\1/;
        p;
    }
' infile

Assuming infile with content:

0
0
01234A56789
1
2
01234Z56789
)
>

Result will be:

A56789
1
2
01234Z

Upvotes: 1

Related Questions