Created
March 28, 2012 17:06
-
-
Save RichardBronosky/2228256 to your computer and use it in GitHub Desktop.
move the last line of a file to the beginning IN PLACE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
file=$1 | |
last=$(tail -n 1 $file) | |
# if you do this in a chmoded file you have to double the backslash as I have in the next line | |
sed -i -e '$d' -e "1 i\\ | |
$last | |
" $file | |
# NOTE: for BSD sed (non-gnu, aka: OSX), use: -i '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
file=$1 | |
ed $file <<EOF | |
\$m0 | |
w | |
q | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment