Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-11-2008, 12:37 AM   #1
Registered: Jun 2004
Location: Gibbons, Alberta, Canada
Distribution: Fedora Core
Posts: 51

Rep: Reputation: 15
Grep to pull specific hyperlinks out of files

Hey people,

Basically I'm looking for a grep command that pulls some Facebook hyperlinks out of multiple text files and dumps all the links into another text file.

Something like

grep -io * > LinkFile.txt

(not sure if I should use -x or not seeing as how the numbers are different)

They are exactly the same except the 10 numbers at the end. I want to find all these links regardless of what the numbers are and push them into a file. If anyone is super ambitious it'd be neat to make it so the same link doesn't get repeated AND/OR make each link clickable in an HTM file.

I've used some simple grep in the past, but I think this might use regular expressions (which I have not much experience). I've tried this a couple times with horrible results.

Anyways, if not an answer, I'm sure a clue or example would get me going.
Old 09-11-2008, 02:00 AM   #2
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 62
Put single quotes around your expressions when they contain shell metacharacters.
grep -io * '' > LinkFile.txt
Use egrep or grep -E to use extended regular expressions. Use the [[:digit:]] character class to match digits. Use the quantifier {10} to indicate that you want 10 of the previous atoms. Use backslash to escape special regular expression characters, such as ?, . (dot) and &.

grep -Eio * 'http://www\.facebook\.com/n/\?inbox/rea...p\&t=[[:digit:]]{10}' > LinkFile.txt


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to grep log for a specific error sfcg Programming 8 06-28-2008 10:12 AM
grep for specific phrases Harry Seldon Linux - Newbie 5 05-27-2008 08:58 PM
How to use grep to search for a specific variable.. memo007 Linux - Software 4 02-24-2007 06:52 PM
An easy way to push and pull files reitzell Linux - Newbie 2 04-27-2005 10:32 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:50 AM.

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