Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

delete to end of line with SED

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-08-2007
coldcanuck coldcanuck is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 8 January 2007, 6:55 PM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Sponsored Links
    #2  
Old Unix and Linux 01-08-2007
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 8 February 2016, 5:12 PM EST
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts
How about this ?


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

Sponsored Links
    #3  
Old Unix and Linux 01-08-2007
tayyabq8's Unix or Linux Image
tayyabq8 tayyabq8 is offline Forum Advisor  
Ex-Moderator
 
Join Date: Nov 2004
Last Activity: 21 May 2016, 8:37 AM EDT
Location: Oman
Posts: 593
Thanks: 8
Thanked 12 Times in 5 Posts
As per your given example:
Code:
$echo "Good Text<extraneous characters" | sed -n -e 's/^\([^<]*\)<.*/\1/p'
Good Text

    #4  
Old Unix and Linux 01-09-2007
mahabooba mahabooba is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 10 January 2007, 12:07 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hi

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

Regards,
MahaboobAli
Sponsored Links
    #5  
Old Unix and Linux 01-09-2007
Glenn Arndt's Unix or Linux Image
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
 
Join Date: Feb 2006
Last Activity: 2 February 2012, 9:30 AM EST
Location: Indianapolis, IN
Posts: 255
Thanks: 0
Thanked 2 Times in 2 Posts
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).
Code:
sed -e :a -e 's/<[^>]*>//g;/</N;//ba' myfile.html

Sponsored Links
    #6  
Old Unix and Linux 07-01-2008
pondlife pondlife is offline
Registered User
 
Join Date: May 2004
Last Activity: 11 April 2012, 11:46 AM EDT
Location: UK
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
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:

Quote:
NUMBER [12345678]
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):


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

Thanks!
Sponsored Links
    #7  
Old Unix and Linux 07-01-2008
pondlife pondlife is offline
Registered User
 
Join Date: May 2004
Last Activity: 11 April 2012, 11:46 AM EDT
Location: UK
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
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 Linux
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete line with match and previous line quoting/escaping problem tomas.polak Shell Programming and Scripting 4 01-17-2012 11:06 AM
Sed or Grep to delete line containing patter plus extra line rocketman88 Shell Programming and Scripting 2 06-30-2010 06:59 AM
Find Pattern delete line and next line rdhanek UNIX for Dummies Questions & Answers 1 07-28-2009 06:25 AM
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 09:25 PM
how to delete line with matching text and line immediately after orahi001 UNIX for Dummies Questions & Answers 6 01-14-2008 11:34 PM



All times are GMT -4. The time now is 02:46 AM.