delete to end of line with SED

I have a file with a bunch of similar lines in which I want to extract a phrase delimited by the first occurance of a '>' at the beginning and the first occurance of a '<' at the end (you might have guessed these are beginning/end of HTML tags). Using Sed I have managed to delete up to and including th first '>'. Now I want to delete from the '<' to the end of each line.

e.g.
Good Text<extraneous characters

I want to delete the '<extraneous characters' part.

Any suggestions?

How about this ?

sed -n -e "s/^[^<]*<\([^>]*\)>.*/\1/p"

As per your given example:

$echo "Good Text<extraneous characters" | sed -n -e 's/^\([^<]*\)<.*/\1/p'
Good Text

Hi,
It may useful to U.
$echo "Good Text<extraneous characters" | cut -d "<" -f1

Regards,
MahaboobAli

Here's a sed command to try -- it's supposed to remove HTML tags. I don't know how well it works (I didn't write it).

sed -e :a -e 's/<[^>]*>//g;/</N;//ba' myfile.html

I'm attempting something similar - I'm trying to identify the following and then remove it as well as anything that comes after it on the line:

I've played around with the code above but I can't seem to get my head around the regular expression.

I've got this so far (but it doesn't work):

sed -n -e 's/NUMBER \[[0-9]*\].*/\1/p'

Thanks!

sed -i -n -e 's/NUMBER \[[0-9]*\].*/NUMBER /p'

I've found the above code works but it removes all lines that don't match too... Anyone know how I can have the above work but leave lines that don't match the pattern intact?

many thanks :slight_smile:

\1 is used when you have grouped parenthesis. In your code, you don't have them. so it will not work. use substitution instead. assuming always 8 digits

sed 's/NUMBER \[.\{8\}\].*//' file