LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2012, 06:59 PM   #1
qjiang
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Problem with deleting content via sed


hello all,

I want to extract part of URL from a webpage, two same addresses are extracted,sed doesn't work for deleting the second one

please see the code
Code:
wget http://www.openstreetmap.org/traces;

while read line
do
  var=$(echo $line|grep -oE '/user/[^/]+/traces/[0-9]+'|sed 's:\ .*$::')
  if [[ -n "$var" ]]
    then
        echo $var
        break
  fi
done<traces

rm traces
Thanks!

Last edited by Tinkster; 03-25-2012 at 07:37 PM. Reason: Fixed closing code tag
 
Old 03-25-2012, 07:43 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!


I can't see a single line w/ a backslash in there when I manually do your wget
& grep here ... I'd be surprised if that sed worked on anything at all.
Code:

grep -oE '/user/[^/]+/traces/[0-9]+' traces |sort -u
/user/DanHomerick/traces/1201497
/user/fmoris/traces/1201462
/user/fmoris/traces/1201463
/user/GPSies_com/traces/1201433
/user/GPSies_com/traces/1201460
/user/jobber_man/traces/1201482
/user/jobber_man/traces/1201487
/user/jobber_man/traces/1201489
/user/jobber_man/traces/1201490
/user/jobber_man/traces/1201491
/user/jobber_man/traces/1201492
/user/Johnmb/traces/1201465
/user/medoreef/traces/1201457
/user/Pitman/traces/1201439
/user/Pitman/traces/1201468
/user/s%C3%BCdpf%C3%A4lzer/traces/1201483
/user/s%C3%BCdpf%C3%A4lzer/traces/1201484
/user/Strassengerl/traces/1201431
/user/swiftfish/traces/1201470
/user/xlv/traces/1201467
Cheers,
Tink

P.S.: I renamed your thread to something I felt was more sensible than
"question", and I fixed your code-tag....

Last edited by Tinkster; 03-25-2012 at 07:44 PM.
 
Old 03-25-2012, 09:40 PM   #3
qjiang
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
thanks, and further question

Thanks for your idea, I fix that out.

There's another further question. Because I only need the latest link, so I use a loop to grep the line and break the loop after successfully finding out one information. However, I noticed there might be another way by using "grep -m 1 user traces" I get the infomation from the man grep and tried but failed. Is this possible to help avoid using loop to read the file line by line? Why it dosn't work?

Thanks

-Kim
 
Old 03-25-2012, 10:01 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Works here ... I still haven't fully understood what it is you're trying
to achieve with all this ... you want the first (at the top of the list)
user submitted line?

Code:
$ grep  -m1 -oE '/user/[^/]+/traces/[0-9]+' traces 
/user/DanHomerick/traces/1201497


Cheers,
Tink
 
  


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
[SOLVED] deleting periods using sed nourah Programming 10 08-23-2011 12:32 PM
Searching and deleting using Sed gregarion Programming 9 01-10-2010 08:51 AM
merging content of two files using sed or awk mukherjee_debajyoti Programming 5 11-30-2009 06:43 AM
Probably a simple sed questions for deleting lines... oldcarguy85 Linux - General 4 03-28-2008 08:11 AM
Deleting folder content Azhrarn Linux - Software 4 04-27-2006 05:07 AM


All times are GMT -5. The time now is 07:00 AM.

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