Knowledgebase

extract domain names from .txt file

Posted by hsohail, 01-09-2008, 02:47 AM
hi need a command to extract the domain names from the following .txt file. sss.com 59 01/09/2008 13:45 edd.com 59 01/09/2008 13:45 i want to extact the domains sss.com and edd.com in another txt file.

Posted by david510, 01-09-2008, 03:31 AM
You may use below, if on Linux. egrep 'sss.com|edd.com' file.txt

Posted by apsivam, 01-09-2008, 04:13 AM
to add to this, if you only want domains names sss.com or edd.com and not the whole line use

Posted by fweikeong, 01-09-2008, 04:44 AM
You would want to explore the 'cut' linux shell command. For example, your data is separated by a white space in between column, so you can do a cut command :- cut -d" " -f1 -d" " means delimiter is " ". -f1 means pick field 1 from the every row in the file_name. Hope that helps.

Posted by 040Hosting, 01-09-2008, 05:25 AM
or when needing a new format of the list ; you may explore the awk command. cat yourfile.txt |awk '{print $1}' would give only the domain names at position #1 (devided by spaces on default). cat yourfile.txt | awk '{print $3 $1}' would give the data and the domain name like: 01/09/2008 sss.com 01/09/2008 edd.com hope this helps. awk has a whole bunch of other nice options too.

Posted by david510, 01-09-2008, 05:50 AM
If sss.com and edd.com always occur at first line inside the .txt file, use the following command. The above command puts the result into the file /root/file2.txt

Posted by hsohail, 01-09-2008, 02:18 PM
thanks cut -d" " -f1 worked for me.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
mrtg graph question (Views: 616)
CAn i use my own dns? (Views: 626)


Language:

Client Login

Email

Password

Remember Me

Search