- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script to select text from a line
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2007 06:36 PM
05-13-2007 06:36 PM
Script to select text from a line
I have the following question.
I have a file with several lines in it.
In each line a have the adress off a website, not on a fixed position. I need a script / command to filter out this website.
fe
The file contains
aeratarawww.hp.comqmlkmlk
qdfdwww.google.commmkkm
arewww.gmail.com kmkùkù
I need as output only
www.hp.com
www.google.com
www.gmail.com
Please advise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2007 06:57 PM
05-13-2007 06:57 PM
Re: Script to select text from a line
sed -e 's/^.*www\./www\./' -e 's/\.com.*$/\.com/' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2007 07:11 PM
05-13-2007 07:11 PM
Re: Script to select text from a line
sed -e 's/*.\(www\..*\.com\).*$/\1/' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2007 09:01 PM
05-13-2007 09:01 PM
Re: Script to select text from a line
try something like this, using your file as $1:
#!/usr/bin/sh
while read line
do
STRING1=$(echo ${line%%www\.*})
STRING2=$(echo "${line#$STRING1}" )
STRING3=$(echo ${STRING2##*\.com})
echo ${STRING2%$STRING3}
done <$1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2007 09:11 PM
05-13-2007 09:11 PM
Re: Script to select text from a line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2007 10:13 PM
05-13-2007 10:13 PM
Re: Script to select text from a line
With more error checking.
awk -F"." '/www\./ && /\.com/ {print "www."$2".com"}' filename
If the file will definitely contain the strings as "www.xxx.com" form, then here is a more simplified form:
awk -F"." '{print "www."$2".com"}' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 12:11 AM
05-14-2007 12:11 AM
Re: Script to select text from a line
I find it unlikely that the www just starts after random text and the .com runs into random text as your example suggests. Is there really no seperator of sorts (whitespace?) If there a field lenght/offset indicator elsewhere in the structure?
If the text is all we have, is the www and .com, and a single field between them a complete description, or does the code also have to trigger on .org, .net and what have you not?
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 01:10 AM
05-14-2007 01:10 AM
Re: Script to select text from a line
This sed script is a bit more generic than some of the other solutions:
$ cat urls
aeratarawww.hp.comqmlkmlk
qdfdwww.google.commmkkm
arewww.gmail.com kmkyky
jkddswww.hello.orgafsdjk
wjekwjws1.hp.netfds7u8
weewwemail.dsdsdswww.netsdfjkldskdsj
wwewuiweweb.ieee.orgfdjkdjdk
www.ibm.com
$ sed -e 's/^.*\(...\..*\....\).*$/\1/' urls
www.hp.com
www.google.com
www.gmail.com
www.hello.org
ws1.hp.net
ail.dsdsdswww.net
web.ieee.org
www.ibm.com
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 02:00 AM
05-14-2007 02:00 AM