LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2005, 05:06 PM   #1
farmerjoe
Member
 
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96

Rep: Reputation: 15
Sed Help Needed..Cutting out peice of file


Hello,

I am new to using sed and would like some help achieving this:

I need to delete everything after <br clear="all"> in a file. The full line that that is on looks like this:

Crevan</i></font></div></td></tr></table></div><br clear="all"><p><div id="fooled" class="subhead1">Have We Been Fooled?</div><span id="fooled2" class="subnav2">

I am trying to stay away from using head, tail, and cut to peice apart the file and put it back together. I was told to try to use sed, but dont have any experience with it. Can anyone help me please?!


Thanks!
farmerjoe
 
Old 02-25-2005, 05:39 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

This:

sed 's/\(.*br clear="all">\).*/\1/' infile

is one way of doing it.

A little breakdown of the command:

sed 's/\(.*br clear="all">\).*/\1/' infile
infile is the file that holds the lines you want to check (probably a html file in your case)

sed 's/\(.*br clear="all">\).*/\1/' infile
The search string looks for 2 things:
1) 'anything' (.*) followed by br clear="all">
2) 'anything' thats after the first hit.

The \( and \) are special, everything in between these can be represented by \1 in the replace string (sed 's/\(.*br clear="all">\).*/\1/' infile)

So the above code will print everything that's found between \( and \) and prints only that.

Hope this helps.
 
Old 02-25-2005, 06:05 PM   #3
farmerjoe
Member
 
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96

Original Poster
Rep: Reputation: 15
AHh! Thanks for your help and your helpful explanation. Would have taken me hours just to figure it out myself (i'm a little slow )

-farmerjoe
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on sed and perl needed. cash_05 Programming 7 09-03-2005 04:33 PM
cutting needed information Kendo1979 Linux - Newbie 5 04-21-2005 03:29 PM
sed regular expression help needed Dew Linux - Newbie 1 03-30-2005 02:59 PM
[bash] cutting text with sed Erhnam Programming 3 02-11-2005 04:31 AM
cutting down contents of text file kam_kenneth Linux - Newbie 2 05-22-2004 01:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration