Sriharsha Kalluru
Sriharsha Kalluru

Reputation: 1823

sed to remove from a character to a character

I have certain data like following.

<some-thing>my-data<some-thing>

I would like to search a character '<' and remove till '>' and need a output like following.

my-data

Is there a way to do it with sed?

Upvotes: 0

Views: 120

Answers (4)

Jotne
Jotne

Reputation: 41460

This awk should do it:

echo "<some-thing>my-data<some-thing>" | awk '{gsub(/<[^>]*>/, " ");$1=$1}1'
my-data

Upvotes: 0

Vijay
Vijay

Reputation: 67299

Using Perl:

perl -pe 's/<.*?>//g' your_file

Upvotes: 1

NeronLeVelu
NeronLeVelu

Reputation: 10039

if there is no < and > in your data

sed 's/<[^>]*>//g

if < or > could appear in the data content

sed 's/^<[^>]*>\(.*\)<[^>]*>$/\1/'

assuming that any line having tag < > are in the case.

remark: Often tag start with a <tag> and stop with a </tag>

Upvotes: 0

Barmar
Barmar

Reputation: 782584

sed 's/<[^>]*>//g' inputfile > outputfile

Upvotes: 0

Related Questions