I have the followiing input file and I need to remove all the characters from the strings that appear after the last '/'. I'll also show my expected output below.
input:
/start/one/two/stopone.js
/start/one/two/three/stoptwo.js
/start/one/stopxyz.js
expected output:
/start/one/two/
/start/one/two/three/
/start/one/
I have tried to use sed
but with no luck so far.
You could simply use good old grep
:
grep -o '.*/' file.txt
This simple expression takes advantage of the fact that grep
is matching greedy. Meaning it will consume as much characters as possible, including /
, until the last /
in path.
Original Answer:
You can use dirname:
while read line ; do
echo dirname "$line"
done < file.txt
or sed:
sed 's~\(.*/\).*~\1~' file.txt
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments