Skip to content

Instantly share code, notes, and snippets.

@mike-seger
Last active March 6, 2025 07:23
Show Gist options
  • Save mike-seger/61eada5ed1735cb7d5720ca63f16a510 to your computer and use it in GitHub Desktop.
Save mike-seger/61eada5ed1735cb7d5720ca63f16a510 to your computer and use it in GitHub Desktop.

recipees

Method 1: Using sed

sed -i ':a;/^\n*$/{N;ba};/\n/{:b;/\n$/!{N;bb};s/^\n*//;s/\n*$//}' filename

Method 2: Using awk

awk '{if (NF || !blank) {print; blank=0} else if (!blank) {blank=1}}' filename > temp && mv temp filename

Method 3: Using perl

perl -i -0777 -pe 's/^\n+|\n+$//g' filename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment