sed and tr


Quick reference

Replace text in all files in & under the current directory

find . -type f -exec sed -i 's/old/new/g' {} \;


Because sed works upon newlines, it makes it difficult to actually process newlines. Use tr instead.

# Remove all newlines
tr -d '\n'

# Replace space w/ newlines
tr -s '[[:space:]]' '\n'

# Replace newlines w/ space
tr '\n' ' '

SamatsWiki: CheatSheet/Sed (last edited 2023-02-22 09:30:03 by SamatJain)