Hi ,
Hi I want to know how can i extract file path using sed?
Eg: C:/folder1/abc/file.txt
Now , i want C:/folder1/abc/ only, So that i can move to that directory containing that file . So how can i do it using sed?
Thanks in Advance
Sarbjit
Hi ,
Hi I want to know how can i extract file path using sed?
Eg: C:/folder1/abc/file.txt
Now , i want C:/folder1/abc/ only, So that i can move to that directory containing that file . So how can i do it using sed?
Thanks in Advance
Sarbjit
You don't have to use sed for such a simple task if you're using a bourne-type unix shell:
% f='C:/folder1/abc/file.txt'; printf '%s/\n' "${f%/*}"
C:/folder1/abc/
Anyway, using sed it would be:
% f='C:/folder1/abc/file.txt'; sed 's [^/]*$ '<<<"$f"
C:/folder1/abc/
If your shell does not support here-strings (the <<< syntax), use printf ... | sed ...
There is an external (to the shell) command for that too, it's called dirname.
% f='C:/folder1/abc/file.txt'; dirname "$f"
C:/folder1/abc
alternatively,
file="C:/folder1/abc/file.txt"
path=${file%\/*}
echo $path
C:/folder1/abc