![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Here is one possible solution:
Code:
sed -n -e 's|\(^.*://[a-z.-]*\)/.*|\1|p' file |
|
#3
|
|||
|
|||
|
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
Code:
>sed -n -e 's|\(^.*://[a-z.-]*\)/.*|\1|p' try.t > 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 |
|
#4
|
|||
|
|||
|
awk
I think this one is ok for you.
Code:
awk 'BEGIN{FS="/"}{print$1"/"$2"/"$3}' filename
|
|||
| Google The UNIX and Linux Forums |