|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
perl -pe 's:\.(?!.*\.).*::' file Last edited by elixir_sinari; 02-11-2013 at 08:04 AM.. |
|
#4
|
||||
|
||||
|
Code:
awk -F. '{$NF=""}1 OFS=. | fileShort 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
|
||||
|
||||
|
Code:
sed 's/\.[^.]*$//' file |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
[QUOTE=Jotne;302769106] Code:
awk -F. '{$NF=""}1 OFS=. | fileShort code, but have a bug, it ends the line with a . Try: Code:
awk -F. 'NF--' OFS=. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Code:
awk -Fcom '{print $1FS}' file |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|