[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

grep awk text in variable positions text file

Posted on 2013-06-21
3
Medium Priority
?
571 Views
Last Modified: 2013-06-21
I have text files I need to extract website links from, but they are in variable positions.

These lines will all be in one text file, and I need to find and pull out only the links.

Examples:

I received the link and it is http://www.google.com/
Bob sent me the best website and I sent it to him:http://www.yahoo.com
Please update to http://www.dropbox.com and I'll get it back to you asap.

dos or linux or python suggestions?
0
Comment
Question by:fkn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39266773
In Python:

import re

# file read code modified from http://stackoverflow.com/questions/8369219/how-do-i-read-a-text-file-into-a-string-variable-in-python#answer-8369272
with open('C:\input.txt', 'r') as inFile:
	text = "".join(line.rstrip() for line in inFile)

for match in re.findall('http://[^ ]+', text):
	print(match)

Open in new window

0
 

Author Closing Comment

by:fkn
ID: 39266831
On the money.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39267352
Much easier to do

grep -Po "http://[\w-.]+" file

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question