Bash/remove extension

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<code lang="bash"> function remove_extension { cat - | rev | cut -d . -f 2- | rev } echo "mytestfile.tgz" | remove_extension </code> === Without 'rev' === <code lang="bash"...")
 
m
 
Line 1: Line 1:
<code lang="bash">
+
<source lang="bash">
 
function remove_extension {
 
function remove_extension {
 
cat - | rev | cut -d . -f 2- | rev
 
cat - | rev | cut -d . -f 2- | rev
Line 5: Line 5:
  
 
echo "mytestfile.tgz" | remove_extension
 
echo "mytestfile.tgz" | remove_extension
</code>
+
</source>
  
 
=== Without 'rev' ===
 
=== Without 'rev' ===
<code lang="bash">
+
<source lang="bash">
 
function remove_extension {
 
function remove_extension {
 
cat - | sed -re 's/\./\n/g' | awk 'BEGIN{c=0;l=""}{if(c>=2)printf".";printf"%s",l;l=$1;c++;}'
 
cat - | sed -re 's/\./\n/g' | awk 'BEGIN{c=0;l=""}{if(c>=2)printf".";printf"%s",l;l=$1;c++;}'
 
}
 
}
</code>
+
</source>

Latest revision as of 19:08, 6 September 2012

function remove_extension {
	cat - | rev | cut -d . -f 2- | rev
}
 
echo "mytestfile.tgz" | remove_extension

[edit] Without 'rev'

function remove_extension {
	cat - | sed -re 's/\./\n/g' | awk 'BEGIN{c=0;l=""}{if(c>=2)printf".";printf"%s",l;l=$1;c++;}'
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox