Delete characters from the last "/"

Hi,

I have a text file with some lines like this:

/MEDIA/DISK1/23568742.MOV 
/MEDIA/DISK1/87456321.AVI 
/MEDIA/DISK2/PART1/45753131.AVI 
/IMPORT/44452.WAV 
...

I don't konw how to delete all characters from the last "/" and the text file looks like this:

/MEDIA/DISK1/
/MEDIA/DISK1/
/MEDIA/DISK2/PART1/
/IMPORT/
...

Thank you.

I�aki

sed 's@\(.*/\).*$@\1@' input_file
1 Like

Than you Msabhi it works perfectly.

also:

sed 's/[^/]*$//' infile

or

awk -F/ '{$NF=""}1' OFS=/ infile

Just in case your next question is going to be how to get the file name or other info. Perl has a good way of parsing (that is independent of operating systems):

 perl -ane 'BEGIN { use File::Basename; } {($n,$d,$t)=fileparse(@F); print $d,"\n"}' yourfile
 
basically 
$n  is your filename
$d directory
$t is the type
$ perl -F/ -lane 'pop @F;print join("/",@F),"/";' input.txt
/MEDIA/DISK1/
/MEDIA/DISK1/
/MEDIA/DISK2/PART1/
/IMPORT/
perl -pe 's:(.*/).*:$1:' file
awk '{gsub(/\/[^/]*$/,"")}1' infile