Sunday, March 13, 2022

[SOLVED] Extracting directory name from an absolute path using sed or awk

Issue

I want to split this line

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

to

/home/edwprod/abortive_visit/bin

using sed or awk scripts? Could you help on this?


Solution

May be command dirname is what you searching for?

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

Or if you want sed, so see my solution:

echo /home/edwprod/abortive_visit/bin/abortive_proc_call.ksh | sed 's/\(.*\)\/.*/\1/'


Answered By - 4ndrew
Answer Checked By - Candace Johnson (WPSolving Volunteer)