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


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-11-2013
Registered User
 
Join Date: Mar 2012
Posts: 49
Thanks: 22
Thanked 0 Times in 0 Posts
Remove last pattern

I have a file with entries below.

Code:
domain1.com.http:
domain2.com.49503:

I need this to be sorted like below. ie remove the patten after the last right-hand side . (dot).

Code:
domain1.com
domain2.com

Sponsored Links
    #2  
Old 02-11-2013
Registered User
 
Join Date: Jul 2007
Posts: 133
Thanks: 21
Thanked 0 Times in 0 Posts

Code:
sed "s/\./ /g" file | awk '{print $1,$2}'|sed "s/ /./g"

Actually u can try with more simpler code but this can work too
Sponsored Links
    #3  
Old 02-11-2013
elixir_sinari's Avatar
Gotham Knight
 
Join Date: Mar 2012
Location: India
Posts: 1,370
Thanks: 87
Thanked 476 Times in 456 Posts

Code:
perl -pe 's:\.(?!.*\.).*::' file


Last edited by elixir_sinari; 02-11-2013 at 08:04 AM..
    #4  
Old 02-11-2013
Jotne's Avatar
Registered User
 
Join Date: Dec 2010
Posts: 522
Thanks: 45
Thanked 98 Times in 91 Posts

Code:
awk -F. '{$NF=""}1 OFS=. | file

Short code, but have a bug, it ends the line with a .

Code:
domain1.com.
domain2.com.

Maybe I find a way to remove it
Sponsored Links
    #5  
Old 02-11-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,348
Thanks: 144
Thanked 1,755 Times in 1,592 Posts

Code:
sed 's/\.[^.]*$//' file

Sponsored Links
    #6  
Old 02-11-2013
Registered User
 
Join Date: Feb 2013
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
[QUOTE=Jotne;302769106]
Code:
awk -F. '{$NF=""}1 OFS=. | file

Short code, but have a bug, it ends the line with a .
Try:
Code:
awk -F. 'NF--' OFS=.

Sponsored Links
    #7  
Old 02-11-2013
Registered User
 
Join Date: Aug 2009
Posts: 201
Thanks: 37
Thanked 24 Times in 24 Posts

Code:
awk -Fcom '{print $1FS}' file

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove all line below the pattern james1988 Shell Programming and Scripting 8 03-22-2012 12:02 PM
remove pattern with sed a27wang Shell Programming and Scripting 5 09-17-2010 12:32 PM
How to remove all text except pattern Lukasito Shell Programming and Scripting 13 01-05-2010 09:15 PM
Program to remove a pattern arsheshadri UNIX for Advanced & Expert Users 4 06-26-2008 12:00 PM
sed remove everything up to the pattern katrvu Shell Programming and Scripting 4 04-08-2008 09:35 PM



All times are GMT -4. The time now is 03:34 PM.