please help, find domain names in string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting please help, find domain names in string
# 1  
Old 01-09-2009
Java please help, find domain names in string

Hello,

i have a file contains the information like below

/home/username/domain.com/log/access
/home/username/domain23.net/log/access
/home/reseller/username/domain.com/log/access

using a loop i can read every line of the file but i wants to extract domain name like(domain.com, domain23.net) from every line

please help me what is the easiest way to do so

Thanks
# 2  
Old 01-09-2009
Not sure if you will always have the string "domain" in your domains so I took the part where a dot is in the string between the slashes:

Code:
root@isau02:/data/tmp/testfeld> cat infile
/home/username/domain.com/log/access
/home/username/domain23.net/log/access
/home/reseller/username/domain.com/log/access
root@isau02:/data/tmp/testfeld> sed 's!.*\/\([^\/]*\.[^\/]*\)/.*!\1!' infile
domain.com
domain23.net
domain.com

# 3  
Old 01-09-2009
Assuming a "domain name" is a name that includes up to two dots, you could do:
Code:
while read line; do
   domain=`perl -e '$ARGV[0]=~ m:/(\w+\.\w+(\.\w+)?)/: && print $1,"\n"' $line`
   echo $domain
done

Here's a similar idea with awk:
Code:
 hostname=`echo  /home/username/domain23.net.au/log/access |
       awk 'BEGIN { RS="/"; } /[[:alnum:]]+\.[[:alnum:]](\.[[:alnum:]])?/'`

Note: If your domains contains dashes, you need to re-work the regular expression.

I'm looking forward to a solution using sed.

Last edited by otheus; 01-09-2009 at 06:10 AM.. Reason: ending backtick
# 4  
Old 01-09-2009
thank you so much. Zaxxon..

it helped me ... that's what i was looking for

Thanks again... you are guru
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find string in file and find the all records by string

Hello I would like to get know how to do this: I got a big file (about 1GB) and I need to find a string (for instance by grep ) and then find all records in this file based on a string. Thanks for advice. Martin (12 Replies)
Discussion started by: mape
12 Replies

2. UNIX for Dummies Questions & Answers

Get domain names from IP addresses of apache2 access.log

I am totally new to shell scripting. I want to see people from which domain access my website. I want to generate the domain names from IP addresses in the Apache access.log file. There are around 54 log files. I concatenate all the files into one. I am using Ubuntu 12.04 LTS. So I... (4 Replies)
Discussion started by: Ronni
4 Replies

3. Shell Programming and Scripting

Get file names from string

Hello folks, would like as for your help. I'm downloading list of files which need to be downloaded later. Via curl I'm getting this output: % Total % Received % Xferd Average Speed Time Curr. Dload Upload Total Current Left ... (3 Replies)
Discussion started by: brusell
3 Replies

4. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

5. Shell Programming and Scripting

Extract all proper names from string with awk

I want to extract the proper names with awk from a very long string, like: õ(k): &lt;/span&gt;<br /><a something="pls/pe/person.person?i_pers_id=3694&amp;i_topic_id=2&amp;i_city_id=3372&amp;i_county_id=-1" target="_blank"><b>Gary Oldman</b></a> (George Smiley)<br /><a... (12 Replies)
Discussion started by: lyp
12 Replies

6. Windows & DOS: Issues & Discussions

How to: Linux BOX in Windows Domain (w/out joining the domain)

Dear Expert, i have linux box that is running in the windows domain, BUT did not being a member of the domain. as I am not the System Administrator so I have no control on the server in the network, such as modify dns entry , add the linux box in AD and domain record and so on that relevant. ... (2 Replies)
Discussion started by: regmaster
2 Replies

7. Shell Programming and Scripting

extracting domain names out of a text file

I am needing to extract and list domain names out of a very large text file. The text file contains tlds .com .net .org and others as well as third level domains e.g. host1.domain.com and the names are placed within paragraphs of text. Domains do not have a http:// prefix so I'm thinking the... (6 Replies)
Discussion started by: totus
6 Replies

8. Shell Programming and Scripting

sorting names after doing a find

hi all, is there an easy way in ksh to sort the results of a find in say alphabetical order ?? e.g in my script i am doing a find for all servers find . -name "server.xml" and the output is not in any order. thanks in advance. (4 Replies)
Discussion started by: cesarNZ
4 Replies

9. UNIX for Dummies Questions & Answers

Using Sendmail for multiple domain names

Hi, We're an internet company with several domain names. Our mail server was originally set up to deal with xxx@domain1.com email addresses which works fine. The problem I have is that we're now also using a domain2.com, and sales@domain1.com isn't the same as sales@domain2.com. I've added... (1 Reply)
Discussion started by: captainash
1 Replies

10. IP Networking

using unregistered domain names

hey what the hell happens if you make sure (as best one can) that a domain name like anything.com is not used at all, and you set up your own DNS and use that name without registering with a registrar, i know if the address is in use you will make some people very upset and give many internet users... (2 Replies)
Discussion started by: norsk hedensk
2 Replies
Login or Register to Ask a Question