I need the following sed one-liner periodically, and I thought it was useful enough to share here. Other versions I’ve seen chopped off everything after the first dot, which doesn’t work for files with a dot in the basename. This one does:
sed s/\.[^\.]*$//
Sample Usage:
bsterne@zodiac:~$ ls /video | sed s/\.[^\.]*$// | head -n5 2001: A Space Odyssey 40 Year Old Virgin, The 9 A Bronx Tale A Clockwork Orange
Why not simply use bash parameter expansion as follows :
“i” being the variable storing the file name :
FILENAME=”${i%.*}”; # matches longuest chain until last “.” is met.
FILEEXT=”${i##*.}”; # matches shortest chain starting with a “.” (so usually the extension)
How i cant remove using sed , in
ls -la | awk ‘{print$09}’
This show a list of folders , but each folder finish in “/”
i need remove that “/” in the final of name