Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Created March 28, 2012 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBronosky/2228256 to your computer and use it in GitHub Desktop.
Save RichardBronosky/2228256 to your computer and use it in GitHub Desktop.
move the last line of a file to the beginning IN PLACE
#!/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 ''
#!/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