星期五, 2月 26, 2021

How to get the last column by Linux command

 A.txt

+++ begin A.txt +++ 

ABC/123/xyz

DEF/456/uvw

+++ end A.txt +++

Would like to get the last column: ( / as the delimiter)

expect output:

xyz

uvw


Method 1: 

awk -F"/" '{print $NF} A.txt


Method 2:

rev A.txt|cut -d '/' -f 1|rev


Method 3:

grep -o '[^/]*$' A.txt


Method 4:

perl -pe 's/(.*)\/(.*)$/$2/' A.txt


ref:

https://stackoverflow.com/questions/22727107/how-to-find-the-last-field-using-cut


沒有留言: