Operating System - HP-UX
1748198 Members
2687 Online
108759 Solutions
New Discussion юеВ

Re: grep the last string in a file

 
SOLVED
Go to solution
kobylka
Valued Contributor

Re: grep the last string in a file

Hi!


sed 's/.*\.//' /tmp/portslist


Kind regards,

Kobylka
Hein van den Heuvel
Honored Contributor

Re: grep the last string in a file

Dennis wrote:

>>Hein: If for some reason using "." as field separator does not work
>It works fine. One char field separators are fixed. If more than one, it is an ERE.

Right. Of course it works. I was not explicit enough.
I meant if it does not work for the exact usage.
You may have noticed how the questions and examples posted here do not always exactly match the real problem :-). Or perhaps a somewhat similar problem of a future reader.
The ERE can more readily be tweaked for more complex matches than a simple 'split'.

Jim wrote
>> perl -ne '@F=split /\./;print $F[@F-1]' file

Well, if you go that route, then you might as well use the build in autosplit ( -a + -F ):

$ perl -F'\.' -lane 'print $F[@F-1]' x

Hein

Laurent Menase
Honored Contributor

Re: grep the last string in a file

while read a
do
echo ${a##*.}
done
Vijaya Kumar_3
Respected Contributor

Re: grep the last string in a file

Thx everyone, I learned a lot from you guys in this thread.


Regards
Vijay Chinnasamy
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Steven Schweda
Honored Contributor

Re: grep the last string in a file

> sed 's/.*\.//' /tmp/portslist

_Much_ too simple. (I might _never_ think of
it.)