How can I do these in sed?
#input #output
file.txt "nothing"
dir1/ ../
dir1/file.txt ../
dir1/dir2/ ../../
dir1/dir2/file.txt ../../
Let's say #input is placed to $var1
sed "do something" <<< $var1
echo $var1
You can try this GNU sed
sed "s#dir[0-9]\+/*#\.\./#g; s#file\.txt##g"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With