You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>echo'🍎\n🍊\n🍎'> foo.txt && cat foo.txt
🍎
🍊
🍎
> sed 's/🍎/🍋/' foo.txt
🍋
🍊
🍋
# in-place# NB: BSD sed requires '' after -i, while GNU sed does not.> sed -i '''s/🍎/🍋/' foo.txt && cat foo.txt
🍋
🍊
🍋
How to delete blank lines, including whitespace-only lines, in a file
How to delete blank lines, excluding whitespace-only lines, in a file
>echo'🍎\n\n \n🍎'> foo.txt && cat foo.txt
🍎
(blank line)
(two spaces)
🍎
> sed -e '/^$/d' foo.txt
🍎
(two spaces)
🍎
# in-place# NB: BSD sed requires '' after -i, while GNU sed does not.> sed -i -e '/^$/d' foo.txt && cat foo.txt
🍎
(two spaces)
🍎
How to delete strings in a file
>echo'🍎\n🍊\n🍎'> foo.txt && cat foo.txt
🍎
🍊
🍎
> sed 's/🍎//g' foo.txt
(blank line)
🍊
(blank line)
# in-place# NB: BSD sed requires '' after -i, while GNU sed does not.> sed -i '''s/🍎//g' foo.txt && cat foo.txt
(blank line)
🍊
(blank line)
How to prefix lines in a file
>echo'🍎\n🍊'> foo.txt && cat foo.txt
🍎
🍊
> sed 's/^/🍋/' foo.txt
🍋🍎
🍋🍊
# in-place# NB: BSD sed requires '' after -i, while GNU sed does not.
sed -i '''s/^/🍋/' foo.txt && cat foo.txt
How to suffix lines in a file
>echo'🍎\n🍊'> foo.txt && cat foo.txt
🍎
🍊
> sed 's/$/🍋/' foo.txt
🍎🍋
🍊🍋
# in-place# NB: BSD sed requires '' after -i, while GNU sed does not.> sed -i '''s/$/🍋/' foo.txt && cat foo.txt
🍎🍋
🍊🍋