The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with tr command ravi raj kumar UNIX for Advanced & Expert Users 2 07-02-2007 03:41 AM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 07:10 AM
ls command problem buckhtr77 SUN Solaris 2 12-06-2005 01:16 PM
Problem while using Sed command gopskrish UNIX for Dummies Questions & Answers 2 06-27-2005 08:26 AM
Sed command problem tomapam Shell Programming and Scripting 1 12-20-2002 05:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
problem in awk command

Hello all,

i am new one to this forum.
:[bash]

i have file with these contents..
internal://project/squid-internal-static/icons/anthony-xpm.gif
http://widget.blogrush.com/img/br.png
http://www.wingware.com/css/print
http://publib.boulder.ibm.com/infoce...terwarning.css
http://www.blogger.com/img/navbar/1/corner.gif
ftp://shan.org/pdg/asd/bin.jpg
ftp://pop.ces.co.uk/qwer/gft.js
.....................................................
....................................................
....................................................
....................................................

i try try print only the domains.Like

internal://project
http://widget.blogrush.com
Wingware Python IDE - The Intelligent Development Environment for Python Programmers
ftp://pop.ces.co.uk

My problem is every line start with differently.Like
http://, ftp:// ...

and end with .co.uk , .co.in , .com

i try awk command.

awk 'BEGIN{OFS=FS="/"} {print $1 $2}' filename

but o/p is

internal:
http:
ftp:
http:

Pls help me.
Reply With Quote
Forum Sponsor
  #2  
Old 02-29-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Here is one possible solution:

Code:
sed -n -e 's|\(^.*://[a-z.-]*\)/.*|\1|p'  file
Reply With Quote
  #3  
Old 02-29-2008
Registered User
 

Join Date: Jan 2007
Location: Detroit
Posts: 81
Probably, all your problem are in forgetting to put back delimiter '/'
It works for me:
Code:
> cat > try.t
internal://project/squid-internal-static/icons/anthony-xpm.gif
http://widget.blogrush.com/img/br.png
http://www.wingware.com/css/print
http://publib.boulder.ibm.com/infoce...terwarning.css
http://www.blogger.com/img/navbar/1/corner.gif
ftp://shan.org/pdg/asd/bin.jpg
ftp://pop.ces.co.uk/qwer/gft.js
^C
>nawk -F/ '{ print $1"/"$2"/"$3; }' try.t
internal://project
http://widget.blogrush.com
http://www.wingware.com
http://publib.boulder.ibm.com
http://www.blogger.com
ftp://shan.org
ftp://pop.ces.co.uk
fpmurphy: your solution does not works for me some why.
Code:
>sed -n -e 's|\(^.*://[a-z.-]*\)/.*|\1|p' try.t
>
[/quote]
The tag does not works. Whithout tag it works:
Code:
c> sed -n  's|^.*://[a-z.-]*/|lll_|p' try.t
lll_squid-internal-static/icons/anthony-xpm.gif
lll_img/br.png
lll_css/print
lll_infoce...terwarning.css
lll_img/navbar/1/corner.gif
lll_pdg/asd/bin.jpg
lll_qwer/gft.js
>
c> alias sed
bash: alias: `sed' not found
> which sed
/bin/sed
Any idea why?
Reply With Quote
  #4  
Old 03-03-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
awk

I think this one is ok for you.

Code:
awk 'BEGIN{FS="/"}{print$1"/"$2"/"$3}' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0