Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Remove last pattern

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-11-2013
anil510 anil510 is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 16 March 2015, 2:50 AM EDT
Posts: 100
Thanks: 47
Thanked 2 Times in 2 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 Unix and Linux 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 Unix and Linux 02-11-2013
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 16 March 2015, 7:53 AM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts

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


Last edited by elixir_sinari; 02-11-2013 at 08:04 AM..
    #4  
Old Unix and Linux 02-11-2013
Jotne's Unix or Linux Image
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
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 Linux
Sponsored Links
    #5  
Old Unix and Linux 02-11-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 22 May 2015, 12:00 PM EDT
Location: Amsterdam
Posts: 10,201
Thanks: 332
Thanked 2,692 Times in 2,408 Posts

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

Sponsored Links
    #6  
Old Unix and Linux 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 12:12 AM.