Delete everything before last / in bash

后端 未结 4 2098
无人共我
无人共我 2021-01-04 22:48

I have many file paths in a file that look like so:

/home/rtz11/files/testfiles/547/prob547455_01

I want to use a bash script that will pri

4条回答
  •  一向
    一向 (楼主)
    2021-01-04 23:30

    awk '{print $NF}' FS=/ input-file
    

    The 'print $NF' directs awk to print the last field of each line, and assigning FS=/ makes forward slash the field delimeter. In sed, you could do:

    sed 's@.*/@@' input-file
    

    which simply deletes everything up to and including the last /.

提交回复
热议问题