The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 06:41 AM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 10:10 AM
ls command problem buckhtr77 SUN Solaris 2 12-06-2005 04:16 PM
Problem while using Sed command gopskrish UNIX for Dummies Questions & Answers 2 06-27-2005 11:26 AM
Sed command problem tomapam Shell Programming and Scripting 1 12-20-2002 08:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-29-2008
viveksnv viveksnv is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 7
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.
  #2 (permalink)  
Old 02-29-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
Here is one possible solution:

Code:
sed -n -e 's|\(^.*://[a-z.-]*\)/.*|\1|p'  file
  #3 (permalink)  
Old 03-01-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
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?
  #4 (permalink)  
Old 03-03-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
awk

I think this one is ok for you.

Code:
awk 'BEGIN{FS="/"}{print$1"/"$2"/"$3}' filename
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0