Extracting directory name from an absolute path using sed or awk

后端 未结 6 1056
忘掉有多难
忘掉有多难 2021-01-05 13:29

I want to split this line

/home/edwprod/abortive_visit/bin/abortive_proc_call.ksh

to

/home/edwprod/abortive_visit/bin
         


        
6条回答
  •  北海茫月
    2021-01-05 14:33

    dirname

    kent$  dirname "/home/edwprod/abortive_visit/bin/abortive_proc_call.ksh"
    /home/edwprod/abortive_visit/bin
    

    sed

    kent$  echo "/home/edwprod/abortive_visit/bin/abortive_proc_call.ksh"|sed 's#/[^/]*$##'
    /home/edwprod/abortive_visit/bin
    

    grep

    kent$  echo "/home/edwprod/abortive_visit/bin/abortive_proc_call.ksh"|grep  -oP '^/.*(?=/)'
    /home/edwprod/abortive_visit/bin
    

    awk

    kent$  echo "/home/edwprod/abortive_visit/bin/abortive_proc_call.ksh"|awk -F'/[^/]*$' '{print $1}'
    /home/edwprod/abortive_visit/bin
    

提交回复
热议问题