Remove last pattern | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Remove last pattern

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-11-2013
anil510 anil510 is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 22 January 2014, 5:17 AM EST
Posts: 74
Thanks: 38
Thanked 1 Time in 1 Post
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
cdfd123 cdfd123 is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 20 July 2013, 1:08 PM EDT
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
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 18 April 2014, 12:09 AM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 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
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 8 April 2014, 11:00 AM EDT
Posts: 1,036
Thanks: 61
Thanked 216 Times in 204 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
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 19 April 2014, 3:36 PM EDT
Location: Amsterdam
Posts: 8,877
Thanks: 230
Thanked 2,141 Times in 1,922 Posts

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

Sponsored Links
    #6  
Old 02-11-2013
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
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
cabrao cabrao is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 15 April 2013, 7:39 AM EDT
Posts: 201
Thanks: 37
Thanked 24 Times in 24 Posts

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

Sponsored Links
Closed Thread

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:41 PM.