Skip to content

Instantly share code, notes, and snippets.

@shaybensasson
Last active March 23, 2020 21:56
Show Gist options
  • Select an option

  • Save shaybensasson/7d03de2fb4b1d0d9905576a339e48c21 to your computer and use it in GitHub Desktop.

Select an option

Save shaybensasson/7d03de2fb4b1d0d9905576a339e48c21 to your computer and use it in GitHub Desktop.
edit HUGE text files selectively using nano
#!/bin/sh
# From here: https://stackoverflow.com/a/29269913
# by: https://stackoverflow.com/users/122422/b-t
# based on: https://stackoverflow.com/a/6874645/1640414
# Usage: hfnano.sh yourHugeFile 3 8
# hint: put in your /usr/bin
if [ "$#" -ne 3 ]; then
echo "Usage: $0 hugeFilePath startLine endLine" >&2
exit 1
fi
sed -n -e $2','$3'p' -e $3'q' $1 > hfnano_temporary_file
nano hfnano_temporary_file
(head -n `expr $2 - 1` $1; cat hfnano_temporary_file; sed -e '1,'$3'd' $1) > hfnano_temporary_file2
cat hfnano_temporary_file2 > $1
rm hfnano_temporary_file hfnano_temporary_file2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment